1 卸载原来的MySQL版本
移除之前部署的mysql软链接
# unlink /etc/init.d/mysql
# unlink /usr/bin/mysql
2 下载最新的MySQL版本
https://dev.mysql.com/downloads/mysql/8.0.html
我这里直接把地址放在这里:https://cdn.mysql.com//Downloads/MySQL-8.1/mysql-8.1.0-linux-glibc2.28-x86_64.tar.xz
3. 部署安装
3.1 解压
# tar -xf mysql-8.1.0-linux-glibc2.28-x86_64.tar.xz
# mv mysql-8.1.0-linux-glibc2.28-x86_64 mysql
# mv mysql /usr/local/
3.2 添加mysql用户组
检查有无安装过mysql 用户组,没有的话创建。
//检查mysql 用户组是否存在
cat /etc/group | grep mysql
cat /etc/passwd |grep mysql// 创建mysql 用户组和用户
groupadd mysql
useradd -r -g mysql mysql
3.3 更改用户组和用户和权限
更改mysql 目录下所有文件夹所属的用户组和用户,以及权限
# chown -R mysql:mysql /usr/local/mysql
# chmod -R 755 /usr/local/mysql
3.4 编写/etc/my.cnf配置文件
[mysqld]
datadir=/usr/local/mysql/data
log-bin=/usr/local/mysql/data/mysql-bin
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=400
innodb_file_per_table=1
#表名大小写不明感,敏感为
lower_case_table_names=1
3.5 初始化mysql
# cd /usr/local/mysql/bin/
# ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
2023-09-26T14:05:58.288546Z 0 [System] [MY-015017] [Server] MySQL Server Initialization - start.
2023-09-26T14:05:58.289713Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2023-09-26T14:05:58.289734Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2023-09-26T14:05:58.289784Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.1.0) initializing of server in progress as process 519016
2023-09-26T14:05:58.298375Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-09-26T14:05:59.009222Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-09-26T14:06:01.021504Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 1;r<VeicZsN?
2023-09-26T14:06:04.449552Z 0 [System] [MY-015018] [Server] MySQL Server Initialization - end.
3.6 添加软链接,启动mysql
//添加软连接
ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql//重启mysql服务
service mysql restart
3.7 修改密码,开放远程链接
# mysql -u root -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'youpassword';mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
mysql> update user set user.Host='%' where user.User='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
3.8 设置开机自启
//将服务文件拷贝到init.d下,并重命名为mysql
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
//赋予可执行权限
chmod +x /etc/init.d/mysqld
//添加服务
chkconfig --add mysqld
//显示服务列表
chkconfig --list