wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.19-el7-x86_64.tar
清理原有mysql
查找mysql列表
[lidengyin@ldy ~]$ sudo rpm -pa | grep mysql
使用一下命令删除mysql列表
sudo yum mysql-*
如果不存在列表则省略
查找所有mysql目录find / -name mysql
如果存在则删除
rm -rf 目录
查看是否安装mariable并卸载
rpm -qa | grep mariadb
安装mysql依赖包
yum install libaio
安装包解压到指定目录
sudo tar -vxf mysql-8.0.19-el7-x86_64.tar
sudo tar -zxvf mysql-8.0.19-el7-x86_64.tar.gz -C /usr/local/software/mysql/
创建mysql数据存放目录
[lidengyin@ldy mysql-8.0.19-el7-x86_64]$ sudo mkdir mysqldb
给安装目录赋予权限
chmod -R 777 /usr/local/software/mysql/mysql-8.0.19-el7-x86_64
chmod -R 777 /usr/local/software/mysql/mysql-8.0.19-el7-x86_64/mysqldb
创建mysql安装初始化文件,加入一下配置保存
sudo /etc/my.cnf
具体内容
[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=/usr/local/software/mysql/mysql-8.0.19-el7-x86_64
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/software/mysql/mysql-8.0.19-el7-x86_64/mysqldb
# 允许最大连接数
max_connections=10000
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10
# 服务端使用的字符集默认为UTF8
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
default_authentication_plugin=mysql_native_password
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8
开始安装
[lidengyin@ldy bin]$ ./mysqld --initialize --console
保存初始化密码:
[Server] A temporary password is generated for root@localhost: MsiGflS#e0(9
启动mysql[lidengyin@ldy mysql-8.0.19-el7-x86_64]$ cd support-files/
[lidengyin@ldy support-files]$ ls -l
total 20
-rwxrwxrwx 1 mysql mysql 1061 Dec 10 03:53 mysqld_multi.server
-rwxrwxrwx 1 mysql mysql 2048 Dec 10 04:28 mysql-log-rotate
-rwxrwxrwx 1 mysql mysql 10576 Dec 10 04:28 mysql.server
启动
[lidengyin@ldy support-files]$ ./mysql.server start
Starting MySQL. SUCCESS!
将mysql加入系统进程,并设置开机自启动
[lidengyin@ldy support-files]$ cp mysql.server /etc/init.d/mysqld
cp: cannot create regular file ‘/etc/init.d/mysqld’: Permission denied
[lidengyin@ldy support-files]$ sudo cp mysql.server /etc/init.d/mysqld
[lidengyin@ldy support-files]$ service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
开机自启动
sudo systemctl enable mysqld
sudo systemctl restart mysqld
使用初始化密码登录
[lidengyin@ldy bin]$ ./mysql -uroot -p
Enter password:
修改密码
alter user'root'@'localhost' IDENTIFIED with mysql_native_password by '123456'
设置可任意主机登录
use mysql
update user set user.Host='%'where user.User='root';
设置允许远程登录
grant all privileges on *.* to 'root'@'%' ;
flush privileges;