第一步下载MySQL8.0.19目前最新版本
1.检查mysql用户组和用户是否存在,如果没有,则创建
[root@localhost /]# cat /etc/group | grep mysql
[root@localhost /]# cat /etc/passwd |grep mysql
[root@localhost /]# groupadd mysql
[root@localhost /]# useradd -r -g mysql mysql
[root@localhost /]#
2.从官网下载是用于Linux的Mysql安装包
#wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
[root@localhost /]# tar xvf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
[root@localhost /]# ls
mysql-8.0.20-linux-glibc2.12-x86_64
mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
执行命令如下:
解压完成后,可以看到当前目录下多了一个解压文件,移动该文件到/www/server/下,并将文件夹名称修改为mysql
[root@localhost /]# mv mysql-8.0.20-linux-glibc2.12-x86_64 /www/server/
[root@localhost /]# cd /www/server/
[root@localhost /]# mv mysql-8.0.20-linux-glibc2.12-x86_64 mysql
如果/usr/local/下不存在mysql文件夹,直接执行如下命令,也可达到上述效果。
[root@localhost /]# mv mysql-8.0.20-linux-glibc2.12-x86_64 /www/server/mysql
2、在/usr/local/mysql目录下创建data目录
[root@localhost /]# mkdir /www/server/mysql/data
3、更改mysql目录下所有的目录及文件夹所属的用户组和用户,以及权限
[root@localhost /]# chown -R mysql:mysql /www/server/mysql
[root@localhost /]# chmod -R 755 /www/server/mysql
4、编译安装并初始化mysql,务必记住初始化输出日志末尾的密码(数据库管理员临时密码)
[root@localhost /]# cd /www/server/mysql/bin
[root@localhost bin]# ./mysqld --initialize --user=mysql --datadir=/www/server/mysql/data --basedir=/www/server/mysql
编辑配置文件my.cnf,添加配置如下
[mysqld]
datadir=/www/server/mysql/data
port=3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=600
innodb_file_per_table=1
log-error=/www/server/mysql/data/error.log
basedir = /www/server/mysql
cat > /etc/my.cnf<<EOF
[mysqld]
datadir=/www/server/mysql/data
port=3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=600
innodb_file_per_table=1
log-error=/www/server/mysql/data/error.log
basedir = /www/server/mysql
EOF
测试启动mysql服务器
[root@localhost /]# /www/server/mysql/support-files/mysql.server start
如果启动报错
Starting MySQL.. ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid)
说的很明白,找不到Mysql server了,于是赶紧的查看my.cnf配置,发现里面少一项basedir,找到mysql安装位置,添加如下
[mysqld]
############# 添加下面这一条配置安装目录###########
datadir = /usr/local/mysql/data
如果报错Starting MySQL. ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid).
####### 添加下面这一条配置安装目录
basedir = /www/server/mysql
如果启动报
[root@localhost init.d]# mysql -u root -p
mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
解决办法:
sudo ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5
其他报错Starting MySQL.2020-07-23T15:47:28.490747Z mysqld_safe error: log-error set to '/www/server/mysql/data/error.log', however file don
请在目录 /www/server/mysql/data/ 创建error.log
添加软连接,并重启mysql服务
ln -s /www/server/mysql/support-files/mysql.server /etc/init.d/mysql
ln -s /www/server/mysql/bin/mysql /usr/bin/mysql
service mysql restart
登录mysql,修改密码(密码为步骤5生成的临时密码)
[root@localhost /]# mysql -u root -p
Enter password:
mysql>ALTER USER USER() IDENTIFIED BY 'yourpass';
mysql>flush privileges;
开放远程连接
mysql>use mysql;
msyql>update user set user.Host='%' where user.User='root';
mysql>flush privileges;
设置开机自动启动
1、将服务文件拷贝到init.d下,并重命名为mysql
[root@localhost /]# cp /www/server/mysql/support-files/mysql.server /etc/init.d/mysqld
2、赋予可执行权限
[root@localhost /]# chmod +x /etc/init.d/mysqld
3、添加服务
[root@localhost /]# chkconfig --add mysqld
4、显示服务列表
[root@localhost /]# chkconfig --list