按照原文安装后自己整理,原文地址:http://www.linuxidc.com/Linux/2016-09/135288.htm
账号:root 密码:Zhangle123456!
账号:admin 密码:Admin123456!
service mysqld stop
service mysqld restart
mysql -uroot -p
默认配置文件路径:
配置文件:/etc/my.cnf
日志文件:/var/log//var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid
1、配置YUM源
# 官网下载路径, 下载mysql源安装包shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
# 安装mysql源
shell> yum localinstall mysql57-community-release-el7-8.noarch.rpm
#检查mysql源是否安装成功
shell> yum repolist enabled | grep "mysql.*-community.*"
#出现如下代码:
mysql-connectors-community/x86_64 MySQL Connectors Community 42
mysql-tools-community/x86_64 MySQL Tools Community 55
mysql57-community/x86_64 MySQL 5.7 Community Server 227
2、安装MySQL
shell> yum install mysql-community-server
3、启动MySQL服务
shell> systemctl start mysqld
4、查看MySQL的启动状态
shell> systemctl status mysqld
显示如下:
mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
Active: active (running) since 五 2016-06-24 04:37:37 CST; 35min ago
Main PID: 2888 (mysqld)CGroup: /system.slice/mysqld.service
└─2888 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
6月 24 04:37:36 localhost.localdomain systemd[1]: Starting MySQL Server...6月 24 04:37:37 localhost.localdomain systemd[1]: Started MySQL Server.
5、设置开机启动
shell> systemctl enable mysqld
shell> systemctl daemon-reload
6、修改root本地登录密码
mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。
通过下面的方式找到root默认密码,然后登录mysql进行修改:
shell> grep 'temporary password' /var/log/mysqld.log
显示如下:
其中 默认密码为最后的: CcyrIPRKk5=K
shell> mysql -uroot -p
Enter password: //输入上面查到的密码 CcyrIPRKk5=K
出现如下界面:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.21
Copyright (c) 2000, 2018, 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> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Zhangle123456';
或者
mysql> set password for 'root'@'localhost'=password('Zhangle123456');
注意:mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含: 大小写字母、数字和特殊符号,并且长度不能少于8位 。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误,
#重新输入复杂密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Zhangle123456!';
Query OK, 0 rows affected (0.00 sec)
以下是密码策略,可跳过:
密码策略提示
通过msyql环境变量可以查看密码策略的相关信息:
mysql> show variables like '%password%';
#显示如下:
+---------------------------------------+--------+
| Variable_name | Value |
+---------------------------------------+--------+
| default_password_lifetime | 0 |
| disconnect_on_expired_password | ON |
| log_builtin_as_identified_by_password | OFF |
| mysql_native_password_proxy_users | OFF |
| old_passwords | 0 |
| report_password | |
| sha256_password_proxy_users | OFF |
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 8 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | MEDIUM |
| validate_password_special_char_count | 1 |
+---------------------------------------+--------+
14 rows in set (0.04 sec)
validate_password_dictionary_file:密码策略文件,策略为STRONG才需要
validate_password_length:密码最少长度
validate_password_mixed_case_count:大小写字符长度,至少1个
validate_password_number_count :数字至少1个
validate_password_policy:密码策略,默认为MEDIUM策略
validate_password_special_char_count:特殊字符至少1个
上述参数是默认策略MEDIUM的密码检查规则。
共有以下几种密码策略:
策略 检查规则0 or LOW Length
1 or MEDIUM Length; numeric, lowercase/uppercase, and special characters
2 or STRONG Length; numeric, lowercase/uppercase, and special characters; dictionary file
MySQL官网密码策略详细说明:http://dev.mysql.com/doc/refman/5.7/en/validate-password-options-variables.html#sysvar_validate_password_policy
修改密码策略
在/etc/my.cnf文件添加validate_password_policy配置,指定密码策略
# 选择0(LOW),1(MEDIUM),2(STRONG)其中一种,选择2需要提供密码字典文件
validate_password_policy=0
如果不需要密码策略,添加my.cnf文件中添加如下配置禁用即可:
validate_password = off
重新启动mysql服务使配置生效:
systemctl restart mysqld
7、添加远程登录用户
默认只允许root帐户在本地登录,如果要在其它机器上连接mysql,必须修改root允许远程连接,或者添加一个允许远程连接的帐户,为了安全起见,我添加一个新的帐户:
mysql> GRANT ALL PRIVILEGES ON *.* TO admin'@'%' IDENTIFIED BY 'Admin123456!' WITH GRANT OPTION;
8、配置默认编码为utf8
修改/etc/my.cnf配置文件
vim /etc/my.cnf
在[mysqld]下添加编码配置,如下所示:
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
重新启动mysql服务,
systemctl restart mysqld
登录数据库
mysql -uroot -p
输入密码 //更改后的新密码
查看默认编码如下所示:
mysql>show variables like '%characters%';
显示如下:
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
-------end-------
按照原文安装后自己整理,原文地址:http://www.linuxidc.com/Linux/2016-09/135288.htm