1, linux-安装mysql

安装mysql5.x

  1. 检查安装过mysql
rpm -qa |grep mysql
  1. 添加rpm仓库
wget https://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
  1. 安装rpm包
sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm

-->
-rw-r--r--. 1 root root 6140 11月 12 2015 mysql-community-release-el7-5.noarch.rpm
[root@mysql-master data]# rpm -ivh mysql-community-release-el7-5.noarch.rpm 
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-release-el7-5    ################################# [100%]
<--
  1. 安装mysql
sudo yum install mysql-server
  1. 进入mysql
mysql -uroot -p

-->
[root@mysql-master lib]# mysql -uroot -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
<--

# 解决方案
chown root /var/lib/mysql
service mysqld restart

# 由于第一次登录, 输入密码的地方直接回车
mysql -uroot -p

-->
[root@mysql-master lib]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.49 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
mysql> 
mysql> 
<--
  1. 设置登录密码
mysql> use mysql;

-->
Database changed
<--

mysql> update user set password=password('root') where user='root';
mysql> exit;
-->
Query OK, 0 rows affected (0.00 sec)
Rows matched: 4  Changed: 0  Warnings: 0
mysql> 
<--

# 重启mysql
service mysqld restart
  1. 设置远程连接
GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root";

-->
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root";
Query OK, 0 rows affected (0.00 sec)
<--

mysql> flush privileges;  
mysql> exit
mysql> use mysql;
mysql> select host,user from user;

-->
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select host,user from user;
+--------------+------+
| host         | user |
+--------------+------+
| %            | root |
| 127.0.0.1    | root |
| ::1          | root |
| localhost    |      |
| localhost    | root |
| mysql-master |      |
| mysql-master | root |
+--------------+------+
7 rows in set (0.00 sec)
<--
  1. 关闭防火墙(测试时使用)
[root@mysql-master ~]# service firewalld stop
Redirecting to /bin/systemctl stop firewalld.service

这时候发现用远程可以连接上了