下载
访问MySQL的下载地址:https://dev.mysql.com/downloads/mysql/
选择系统、版本、glic版本后,下载包缩包
https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.39-linux-glibc2.17-x86_64.tar.xz
注:如果不知道该选什么glic版本,可以运行命令:
ldd --version
输出:
ldd (GNU libc) 2.17
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.
表示该机的glic版本是:2.17
解压及启动前的准备
准备好目录:/app_home/, 压缩包在此目录下:/app_home/mysql-8.0.39-linux-glibc2.17-x86_64.tar.xz
解压xz: xz -d mysql-8.0.39-linux-glibc2.17-x86_64.tar.xz
解压tar: tar -xvf mysql-8.0.39-linux-glibc2.17-x86_64.tar
rename: mv mysql-8.0.39-linux-glibc2.17-x86_64 mysql-8.0.39
创建data目前:cd /app_home/mysql-8.0.39/ mkdir ./data
创建MySQL独立用户
groupadd mysql
useradd -g mysql mysql
chown -R mysql .
chgrp -R mysql .
注:非root用户需要在命令前加sudo
初始化密码
cd /app_home/mysql-8.0.39/
./bin/mysqld --user=mysql --basedir=/app_home/mysql-8.0.39/ --datadir=/app_home/mysql-8.0.39/data/ --initialize
查看输出,找到初始密码
配置MySQL密码和访问权限
登录: /app_home/mysql-8.0.39/bin/mysql -h127.0.0.1 -uroot -p'init_password'
修改初始密码: ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_new_password';
开放远程访问MySQL: update user set host = '%' where user = 'root'; 注:% 表示对所有host开放访问,如需要限定IP白名单,可以将此值设为对应的ip
刷新权限:flush privileges;
使用Dbeaver连接该服务器,验证可连接后,执行:select version(); 看到版本号8.0.39表示客户端连接成功。
关闭服务
{spa.aile21.com]
{spa.sinohxht.com]
{spa.hbtzymx.com]
{spa.kani-buro.com]
{spa.lvbo360.com]
{spa.51mushe.com]
{spa.1089club.com]
{spa.huiminqiao.com]
cd /app_home/mysql-8.0.39/
./bin/mysqladmin -uroot -p'your_new_password' shutdown -S /var/lib/mysql/mysql.sock
注:mysql.sock是mysql创建的本地套接字文件,如果报:
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!
则需要像上面命令行一样,加上mysql.sock文件的路径参数
启动服务并挂起
nohup ./bin/mysqld --user=mysql --basedir=/app_home/mysql-8.0.39/ --datadir=/app_home/mysql-8.0.39/data/ &