安装MySQL
1 下载并安装MySQL官方的 Yum Repository
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
然后就可以直接yum安装
yum -y install mysql57-community-release-el7-10.noarch.rpm
之后就开始安装MySQL服务器
yum -y install mysql-community-server
2 MySQL数据库设置
1.重置密码的第一步就是跳过MySQL的密码认证过程,方法如下:
vim /etc/my.cnf
在[mysqld]后面任意一行添加 skip-grant-tables
2.之后重启
systemctl stop mysqld.service
systemctl start mysqld.service
service mysqld restart
3.查看状态
systemctl status mysqld.service
如下为成功启动状态
可查看mysql 的root 密码:grep “password” /var/log/mysqld.log
4.进入mysql
mysql -uroot -p
use mysql;
update user set Password=123456 where user ='root';
如果是新版本会报password不存在;那么就改为下面语句
update user set authentication_string=123456 where user="root";
然后刷新
flush privileges;
输入 exit 进行退出,然后重新启动
最后使用navicat进行测试即可;
如果都调整完后,链接不了,那么就执行下列语句
mysql -u root -p
use mysql;
查看mysql库中的user表的host值:
select 'host' from user where user='root';
修改host值:
update user set host = '%' where user ='root';
刷新MySQL的系统权限相关表:
flush privileges;
select 'host' from user where user='root';
执行后重启mysql即可链接了。