Python mysql

官方文档:http://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/

一、安装mysql

1.配置linux服务器上网

2.配置mysql yum源

http://dev.mysql.com/downloads/repo/yum/

3.安装yum源

rpm -Uvh platform-and-version-specific-package-name.rpm

4.安装mysql

sudo yum install mysql-community-server

5.启动mysql

service mysqld start

6.获取mysql的临时登录密码

grep 'temporary password' /var/log/mysqld.log

7.登录mysql

shell> mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Passw0rd!';

8.用navicat连接mysql

  注意一定要关闭windows防火墙和centos的防火墙

  systemctl stop firewalld.service

修改主机名hostname之后无法登陆:

[root@rabbitmq ~]# mysql -uroot -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

起初以为是权限的问题,后来发现只是主机名修改的原因,改回原来的主机名,登陆进去后查看user表:

mysql> select user,host,authentication_string from user where user='root';
+------+---------------+-------------------------------------------+
| user | host          | authentication_string                     |
+------+---------------+-------------------------------------------+
| root | localhost     | *03F7361A0E18DA99361B7A82EA575944F53E206B |
| root | 192.168.2.103 | *03F7361A0E18DA99361B7A82EA575944F53E206B |
+------+---------------+-------------------------------------------+
2 rows in set (0.00 sec)

原来服务器的IP是'192.168.2.103',但是现在IP变成了'192.168.2.101',所以无法登陆了,重新授权所有的IP都可以访问(%表示任意主机):

mysql> grant all privileges on *.* to 'root'@'%' identified by 'Passw0rd!' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> FLUSH   PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> 
mysql> 
mysql> select user,host from user where user='root';
+------+---------------+
| user | host          |
+------+---------------+
| root | %             |
| root | 192.168.2.101 |
| root | 192.168.2.103 |
+------+---------------+
3 rows in set (0.00 sec)

然后再修改为其他的服务器名字,也可以正常连接了。

原文地址:https://www.cnblogs.com/python-study/p/5860836.html