下载mysql源安装包
[root@ChenBolin ~]# wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
安装mysql源
[root@ChenBolin ~]# yum localinstall mysql57-community-release-el7-8.noarch.rpm
<-- 提示【Is this ok [y/d/N]: y 输入y回车】 -->
# 检查MySQL源是否安装成功
[root@ChenBolin ~]# yum repolist enabled | grep “mysql.-community.”
[root@ChenBolin ~]# yum install mysql-community-server
注意:安装过程中提示【Is this ok [y/d/N]: y 输入y回车】
出现以下表示安装成功:
Dependency Updated:
postfix.x86_64 2:2.10.1-7.el7
Replaced:
mariadb-libs.x86_64 1:5.5.56-2.el7
[root@ChenBolin ~]# systemctl start mysqld
[root@ChenBolin ~]# systemctl status mysqld
[root@ChenBolin ~]# systemctl enable mysqld
[root@ChenBolin ~]# systemctl daemon-reload
mysql5.7安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。
通过下面的方式找到root默认密码,然后登录mysql;
[root@ChenBolin ~]# grep 'temporary password' /var/log/mysqld.log
2019-04-08T14:20:42.853739Z 1 [Note] A temporary password is generated for root@localhost: ?,h?ec:pq5fJ
# 默认密码是:?,h?ec:pq5fJ
修改密码策略
mysql的密码策略分为三种:
在my.cnf文件中增加如下设置
validate_password = off
validate_password_policy = 0
character_set_server = utf8
init_connect = ‘SET NAMES utf8’
# 例:
[root@ChenBolin ~]# cd /etc/
[root@ChenBolin etc]# vi my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
validate_password_policy = 0
character_set_server = utf8 #修改字符编码为utf8
init_connect = 'SET NAMES utf8'
systemctl restart mysqld
mysql -uroot -p
输入初始密码:?,h?ec:pq5fJ
[root@ChenBolin etc]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.25 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> ALTER USER 'root'@'localhost' identified by '19940415';
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on *.* to 'root'@'%' identified by '19940415';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
原文链接:https://www.cnblogs.com/killall007/p/9504673.html