mysql在云服务器中出现的问题以及解决方案(centos7.3

2019-04-02  本文已影响0人  一条IT

1、如果出现:Access denied for user 'root'@'localhost' (using password: YES)

是代表:用户root在本地登录使用密码的时候访问被拒绝,可能是密码输入错误:

解决方案:

①、停止mysql服务的启动:

[root@iZ35pgvwfakdy8Z bin]# systemctl stop mysqld

②、将MySQL调至跳过密码登录:

编辑/etc/my.cnf文件

[root@iZ35pgvwfakdy8Z bin]# vi /etc/my.cnf

然后,在文件中添加一行语句(跳过密码的代码):

skip-grant-tables

如图:

image

保存退出“:wq”。

③、重启MySQL数据库

[root@iZ35pgvwfakdy8Z bin]# systemctl restart mysqld

④、进入mysql的命令行中

[root@iZ35pgvwfakdy8Z bin]# mysql

如图:

image

然后,在里面修改密码:

mysql> use mysql; 
mysql> update user set password=password('123') where user='root' and host='localhost'; 
mysql> flush privileges; 

然后,将文件/etc/my.cnf里面添加的“skip-grant-tables”语句删除。

⑤、重启数据库

[root@iZ35pgvwfakdy8Z bin]# systemctl restart mysqld

⑥、检查修改是否成功:

[root@iZ35pgvwfakdy8Z bin]# mysql -uroot -p 

输入密码,enter回车。

image

上图代表修改成功。
2、如果本地mysql连接云服务器中出现:


image.png

意思就是说只允许本地连接mysql。

解决方案:

[root@iZ35pgvwfakdy8Z bin]# mysql -uroot -p 

输入密码进入mysql执行命令行中。
然后,输入:

mysql>use mysql;
-- 创建用户、密码及权限范围 第一个 roo t为用户名 @后为适用的主机,‘%’表示所有电脑都可以访问连接,第二个 root 为密码

mysql> GRANT ALL PRIVILEGES ON *.* TO '用户名'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;                 
Query OK, 0 rows affected (1.57 sec)

-- 立即生效
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

接着关闭防火墙:

[root@iZ35pgvwfakdy8Z bin]# systemctl stop firewalld

CentOS7使用firewalld打开关闭防火墙与端口
然后重启mysql,本地检查连接是否连接的上。

[root@iZ35pgvwfakdy8Z bin]# systemctl start mysqld
image.png

连接成功。

上一篇 下一篇

猜你喜欢

热点阅读