2.3 RPM安装mysql
[root@localhost mysql]# yum -y install mysql-community-server mysql-devel
2.4 初始化启动mysql
[root@localhost mysql]# service mysqld start
Initializing MySQL database: [ OK ]
Starting mysqld: [ OK ]
[root@gds mysql]# service mysqld stop
Stopping mysqld: [ OK ]
2.5 初始化mysql 配置
- 修改数据库默认编码为: utf-8
- 修改日志,数据,运行id 等目录位置
- 关闭密码强度校验: mysql 5.7在设置密码时, 出于安全考虑新增了密码校验, 建议再生产环境使用, 但是在开发环境就没有必要了, 可以选择关闭. mysql 默认密码校验规则: 由大写字母, 小写字母, 数字, 特殊符合组成的至少8位的密码
修改: /etc/my.cnf
#数据库编码: mysqld 下添加一行
[mysqld]
#指定数据库默认编码
character_set_server = utf8
# 关闭密码校验
validate_password=off
#指定客户端连接默认编码
[client]
default-character-set = utf8
2.6 查看root 初始密码
- 密码为: +)j8KEtxGNUV
[root@gds mysql]# grep 'temporary password' /var/log/mysqld.log
2017-07-26T08:04:47.499031Z 1 [Note] A temporary password is generated for root@localhost: +)j8KEtxGNUV
2.7 登录客户端, 修改root 密码
- 使用mysql 客户端连接mysql数据库: mysql -u 用户名 -p
- 修改root用户名, 我们设置一个简单的密码: root
- 默认情况下root用户不允许从其他电脑登录, 我们授权允许从任何机器上登录
[root@gds mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.19
Copyright (c) 2000, 2017, 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 'root';
Query OK, 0 rows affected (0.04 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)
2.8 查看数据库编码
mysql> show variables like '%char%';
+--------------------------+----------------------------+
| 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/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)