1.先卸载系统原来的mysql
2.按照步骤安装https://blog.csdn.net/ling1998/article/details/124070790
1)创建镜像repo文件
[root@localhost src]# vi /etc/yum.repos.d/mariadb.repo
[mariadb]
name = MariaDB
baseurl = https://mirrors.ustc.edu.cn/mariadb/yum/10.2/centos7-amd64
gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
2)更新yum缓存数据
[root@localhost src]# yum clean all
[root@localhost src]# yum makecache all
(3)安装 & 启动 & 设置开机启动
[root@localhost src]# yum install MariaDB-server MariaDB-client -y
[root@localhost src]# systemctl start mariadb.service
[root@localhost src]# systemctl enable mariadb.service
(4)初始化
[root@localhost src]# mysql_secure_installation
Enter current password for root (enter for none): #初次运行,直接回车
Set root password? [Y/n] Y #是否设置root用户密码,输入Y并回车或直接回车
New password: #设置root用户密码
Re-enter new password: #密码确认
Remove anonymous users? [Y/n] #是否删除匿名用户,回车
Disallow root login remotely? [Y/n] n #是否禁止root远程登录,输入n回车(我需要远程连接)
Remove test database and access to it? [Y/n] #是否删除test数据库,回车
Reload privilege tables now? [Y/n] #是否重新加载权限表,回车
Thanks for using MariaDB!
(5)连接数据库
[root@localhost src]# mysql -uroot -p -h localhost -P 3306
Enter password:
MariaDB [(none)]>
3.设置可以远程访问
1)登录数据库 use mysql;
2)select Host, User,Password from user;
3)update user set Host='%' where User='root';
4)flush privileges;