1、移除时执行以下删除命令
yum remove mysql mysql-server mysql-libs compat-mysql51
rm -rf /var/lib/mysql
rm /etc/my.cnf
2、查看是否还有残留
rpm -qa|grep mysql
如果仍然有,继续删除即可.也可使用命令rpm -e –nodeps {-file-name} 移除。
1、下载 MySQL 官网 https://www.mysql.com/downloads/ 选择下载社区版本(MySQL Community Edition (GPL)),我这里下载的是最新版本 mysql-8.0.12-1.el7.x86_64.rpm-bundle.tar。直接执行命令下载全家桶
wget -c https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.12-1.el7.x86_64.rpm-bundle.tar
2、解压
tar –xvf mysql-8.0.12-1.el7.x86_64.rpm-bundle.tar
3、依次安装
rpm -ivh mysql-community-common-8.0.12-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.12-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-8.0.12-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.12-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-8.0.12-1.el7.x86_64.rpm
rpm -ivh mysql-community-embedded-compat-8.0.12-1.el7.x86_64.rpm
rpm -ivh mysql-community-test-8.0.12-1.el7.x86_64.rpm
rpm -ivh mysql-community-minimal-debuginfo-8.0.12-1.el7.x86_64.rpm
rpm -ivh mysql-community-embedded-compat-8.0.12-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.12-1.el7.x86_64.rpm
rpm -ivh mysql-community-test-8.0.12-1.el7.x86_64.rpm
最后安装的时候遇到一个错误
rpm -ivh mysql-community-embedded-compat-8.0.12-1.el7.x86_64.rpm
error: Failed dependencies:
libaio.so.1()(64bit) is needed by MySQL-server-5.5.25a-1.rhel5.x86_64
libaio.so.1(LIBAIO_0.1)(64bit) is needed by MySQL-server-5.5.25a-1.rhel5.x86_64
libaio.so.1(LIBAIO_0.4)(64bit) is needed by MySQL-server-5.5.25a-1.rhel5.x86_64
解决方法
yum install libaio
注: i-install安装;v-verbose进度条;h-hash哈希校验
4、查看mysql 版本
mysql -V
5初始化MySQL
mysqld --initialize --user=mysql
初始化完成后再下边文件末尾会有随机密码,一会登陆时候用
[root@izbp1dmlbagds9ebtxqnv1z ~]# cat /var/log/mysqld.log
2018-09-04T05:36:57.033445Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.12) initializing of server in progress as process 5245
2018-09-04T05:36:59.925255Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ul8y;iZ)q28,
2018-09-04T05:37:01.331270Z 0 [System] [MY-013170] [Server] /usr/sbin/mysqld (mysqld 8.0.12) initializing of server has completed
备注:如果需要设置大小写敏感,一定要在初始化之前设置.
vim /etc/my.cnf
[mysqld]
default-authentication-plugin=mysql_native_password
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
`
lower_case_table_names = 1
`
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
5、启动MySQL
启动
systemctl start mysqld.service
停止
systemctl stop mysqld.service
重起
systemctl restart mysqld.service
查看状态
systemctl status mysqld.service
6、登录MySQL并修改密码
mysql -u root -p ul8y;iZ)q28,
alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.07 sec)
刷新权限
FLUSH PRIVILEGES;
7、允许远程访问
update user set host='%' where user='root';
Query OK, 1 row affected (0.11 sec)
Rows matched: 1 Changed: 1 Warnings: 0
8、将MySQL写入开机启动项
开机启动
systemctl enable mysqld.service
禁止开机启动
systemctl disable mysqld.service