centos7安装mysql,以及设置root密码

1.首先进入mysql官网的下载-社区https://dev.mysql.com/downloads/

centos7安装mysql,以及设置root密码

2.点击下载后,切换版本5.7选择yum下载链接

centos7安装mysql,以及设置root密码

centos7安装mysql,以及设置root密码

3.在新打开的页面,点击下载rpm文件,在新的页面选择直接下载,获取到下载链接

centos7安装mysql,以及设置root密码

centos7安装mysql,以及设置root密码

4.移除mariadb数据库

yum remove mariadb-libs.x86_64

5.进入到/tmp目录使用wget下载上面得到的连接

wget https://repo.mysql.com//mysql80-community-release-el7-2.noarch.rpm

6.安装mysql的源

yum localinstall mysql80-community-release-el7-2.noarch.rpm 

7.通过查找命令找到社区版的安装文件

yum search mysql

另外,安装yum-config-manager,然后修改要安装的mysql版本为5.7

[root@freesaber tmp]# yum search yum-config-manager
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
========================================== Matched: yum-config-manager ==========================================
yum-utils.noarch : Utilities based around the yum package manager
[root@freesaber tmp]# yum install yum-utils.noarch
yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community

8.安装mysql

yum install mysql-community-server

centos7安装mysql,以及设置root密码

9.开启mysql服务

systemctl start mysqld

10.查看myqsl的默认密码

 cat /var/log/mysqld.log
2019-03-27T03:05:34.627566Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.15) initializing of server in progress as process 29114
2019-03-27T03:05:38.631106Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: I+w=67d;+ES8
2019-03-27T03:05:40.427422Z 0 [System] [MY-013170] [Server] /usr/sbin/mysqld (mysqld 8.0.15) initializing of server has completed
2019-03-27T03:05:42.371036Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.15) starting as process 29161
2019-03-27T03:05:43.074650Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2019-03-27T03:05:43.117341Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.15' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server - GPL.
2019-03-27T03:05:43.166968Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060

11.使用密码进行登陆mysql

 mysql -uroot -p

12.修改设置密码的验证规则

set global validate_password_policy=0;
set global validate_password_length=1;

13.修改root的密码

mysql>  SET PASSWORD = PASSWORD('密码');
Query OK, 0 rows affected, 1 warning (0.00 sec)

14.退出后,使用新密码登陆。查看数据库。

mysql -u root -p
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec) 

15.查看root账户,修改root账户,允许任何主机进行连接

mysql> use mysql;
Database changed
mysql> select Host,User from user \G;
*************************** 1. row ***************************
Host: localhost
User: mysql.infoschema
*************************** 2. row ***************************
Host: localhost
User: mysql.session
*************************** 3. row ***************************
Host: localhost
User: mysql.sys
*************************** 4. row ***************************
Host: localhost
User: root
4 rows in set (0.00 sec)
mysql> update user set Host = '%' where Host = 'localhost' and User = 'root';
Query OK, 1 row affected (0.04 sec)
Rows matched: 1 Changed: 1 Warnings: 0 mysql> select Host,User from user \G;
*************************** 1. row ***************************
Host: %
User: root
*************************** 2. row ***************************
Host: localhost
User: mysql.infoschema
*************************** 3. row ***************************
Host: localhost
User: mysql.session
*************************** 4. row ***************************
Host: localhost
User: mysql.sys
4 rows in set (0.00 sec) ERROR:
No query specified

刷新权限

FLUSH PRIVILEGES;

16.使用Navicat连接mysql(需要关闭firewalld服务,另外阿里云的安全组需要允许访问3306)

systemctl stop firewalld

centos7安装mysql,以及设置root密码

17.开启genelog

mysql> set global general_log_file="/tmp/general.log";
Query OK, 0 rows affected (0.00 sec) mysql> set global general_log=on;
Query OK, 0 rows affected (0.00 sec)
上一篇:关于浏览器兼容问题及hack写法


下一篇:python学习笔记之一:列表与元组