卸载mariadb
# systemctl stop mariadb
# yum remove mariadb
安装MySQL
注意的是,不能在CentOS7下安装MySQL,不能
# yum install mysql-server
结果一定出错
处理方法是,安装MySQL的yum库,然后才能用yum进行安装
参考:How To Install MySQL on CentOS 7,安装yum的MySQL库
# wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
# yum install -y mysql57-community-release-el7-11.noarch.rpm
检查一下yum的库情况
yum repolist enabled | grep mysql.*
mysql-connectors-community/x86_64 MySQL Connectors Community 165
mysql-tools-community/x86_64 MySQL Tools Community 115
mysql57-community/x86_64 MySQL 5.7 Community Server 444
出现这个列表,恭喜你,说明库装上去了,注意哦,这步不是实际安装MySQL,下面进行MySQL的安装
# yum install mysql-community-server
Running transaction check
Running transaction test
Transaction check error:
file /usr/share/mysql/charsets/Index.xml from install of mysql-community-common-5.7.31-1.el7.x86_64 conflicts with file from package MariaDB-common-10.4.13-1.el7.centos.x86_64
file /usr/share/mysql/charsets/armscii8.xml from install of mysql-community-common-5.7.31-1.el7.x86_64 conflicts with file from package MariaDB-common-10.4.13-1.el7.centos.x86_64
file /usr/share/mysql/charsets/ascii.xml from install of mysql-community-common-5.7.31-1.el7.x86_64 conflicts with file from package MariaDB-common-10.4.13-1.el7.centos.
出一堆意外的错误,不知从何下手了呗,唉,从网上找到MySQL的数据库目录,清一下先
# rm -rf /var/lib/mysql
再找找资料,幸好有发现:mysql wont install in CentOS due to conflict with mariadb
# yum shell
> remove mariadb-libs
> run
> --> Running transaction check
---> Package MariaDB-compat.x86_64 0:10.4.13-1.el7.centos will be erased
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: perl-DBD-MySQL-4.023-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-7.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: perl-DBD-MySQL-4.023-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-7.el7.x86_64
--> Processing Dependency: MariaDB-compat for package: MariaDB-common-10.4.13-1.el7.centos.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: perl-DBD-MySQL-4.023-6.el7.x86_64
......
哦,后台有关联的模块都清干净了
再装
# yum install mysql-community-server -y
终于可以了,下面运行下数据库,登录
# systemctl start mysqld
# mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
mysql还不能用空密码登录,参考MySQL 5.7以上 root用户默认密码问题
# grep "temporary password" /var/log/mysqld.log
2020-07-17T03:35:18.371490Z 1 [Note] A temporary password is generated for root@localhost: xxxxxxxxxx
那一堆的XXXXXX就是你的密码了
改一下密码呗,以后进去容易一点了
set password for root@localhost = password('1234');
傻眼了吧?ERROR 1819 (HY000): Your password does not satisfy the current policy requirements,按大神的解决办法:
set global validate_password_length=4;
set global validate_password_policy=0;
MySQL8 之后 修改参数名称变了
set global validate_password.policy=0;
set global validate_password.length=1;
搞定