连仕彤博客Centos7安装Mysql数据库
自从
Mysql
数据库软件被sun公司收购后(后来sun又被Oracle收购),新东家一心一意的想着样把Mysql商业化(就是想卖钱),无奈之下Mysql的作者自己又写了一款开源数据库软件(和Mysql一样,就是换了个名字而已。),并以他女儿的名字maria命名为
MariaDB
。然而在Centos7系统中,使用
yum -y install mysql
的时候,就会安装MariaDB。毕竟Mraidb我个人用着不顺手,所以还是希望安装原汁原味的Mysql。
安装epel reop源
[root@virmach software]# wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
[root@virmach software]# yum localinstall mysql57-community-release-el7-8.noarch.rpm
*[root@virmach software]# rpm -ivh mysql57-community-release-el7-8.noarch.rpm
检查epel reop源
[root@virmach software]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community 45
mysql-tools-community/x86_64 MySQL Tools Community 59
mysql57-community/x86_64 MySQL 5.7 Community Server 247
安装Mysql
[root@virmach software]# yum install mysql-community-server
启动Mysql
[root@virmach software]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: inactive (dead)
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
[root@virmach software]# systemctl start mysqld
[root@virmach software]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2018-03-18 09:34:48 EDT; 3s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 1284 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 1211 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 1288 (mysqld)
CGroup: /system.slice/mysqld.service
└─1288 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Mar 18 09:34:42 virmach systemd[1]: Starting MySQL Server...
Mar 18 09:34:48 virmach systemd[1]: Started MySQL Server.
加入开机启动
[root@virmach software]# systemctl enable mysqld
[root@virmach software]# systemctl daemon-reload
修改root密码
mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:
[root@virmach software]# grep 'temporary password' /var/log/mysqld.log
2018-03-18T13:34:43.195576Z 1 [Note] A temporary password is generated for root@localhost: %Q4pxmlnYwx>
[root@virmach software]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.21
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> set password for 'root'@'localhost'=password('$7Q7xtUdM%Wp');
Query OK, 0 rows affected, 1 warning (0.00 sec)
注意:mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误,如下图所示:
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.01 sec)
validate_password_policy:密码策略,默认为MEDIUM策略 validate_password_dictionary_file:密码策略文件,策略为STRONG才需要 validate_password_length:密码最少长度 validate_password_mixed_case_count:大小写字符长度,至少1个 validate_password_number_count :数字至少1个 validate_password_special_char_count:特殊字符至少1个 上述参数是默认策略MEDIUM的密码检查规则。
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
配置默认编码为utf8 修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:
[mysqld]
character<em>set</em>server=utf8