CentOS 7 the installation and configuration MySQL 5.7

Inscription:

Ali bought the database server is installed, but it seems vaguely before seen in which MySQL does not support Linux systems, (today deliberately looking for a bit and could not find information that is not supported, do not remember where to look up) at the time with the maria DB but when there are a lot of problems with today specifically come back again for a database, the configuration process to do some recording.

In this paper the test environment:

  • CentOS 7 64-bit Minimal
  • MySQL 5.7

Yum configuration source

In https://dev.mysql.com/downloads/repo/yum/ find the source rpm yum install package

rpm installation package

Install mysql source

# 下载
shell> wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
# 安装 mysql 源
shell> yum localinstall mysql57-community-release-el7-11.noarch.rpm

Is installed successfully using the following commands to check the mysql source

shell> yum repolist enabled | grep "mysql.*-community.*"

mysql successful installation source

Installing MySQL

Use yum install command to install

shell> yum install -y mysql-community-server

Start MySQL service

In CentOS 7, a new startup / shutdown services command is systemctl start|stop

shell> systemctl start mysqld

With a systemctl statusview MySQL status

shell> systemctl status mysqld

MySQL start state

Set boot

shell> systemctl enable mysqld
# 重载所有修改过的配置文件
shell> systemctl daemon-reload

Changing the root password for local accounts

mysql After installation is complete, the resulting default password in the /var/log/mysqld.logfile. Use the grep command to find the log password.

shell> grep 'temporary password' /var/log/mysqld.log

View Temporary Password

For the first time by the initial password, use the following command to change the password

shell> mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!'; 

or

mysql> set password for 'root'@'localhost'=password('MyNewPass4!'); 

After modifying password update set statement

mysql> use mysql;
mysql> update user set password=PASSWORD('MyNewPass5!') where user='root';
mysql> flush privileges;

Note: mysql 5.7 installed by default password security check-ins (validate_password), check the default password policy requires password must contain: uppercase and lowercase letters, numbers and special symbols, and the length can not be less than eight. Otherwise it will prompt ERROR 1819 (HY000): Your password does not satisfy the current policy requirements error. View MySQL official website password details strategy

Add Telnet user

默认只允许root帐户在本地登录,如果要在其它机器上连接mysql,必须添加一个允许远程连接的帐户。或者修改 root 为允许远程连接(不推荐)

添加一个允许远程连接的帐户

mysql> GRANT ALL PRIVILEGES ON *.* TO 'zhangsan'@'%' IDENTIFIED BY 'Zhangsan2018!' WITH GRANT OPTION;

修改 root 为允许远程连接(不推荐)

mysql> use mysql;
mysql> UPDATE user SET Host='%' WHERE User='root';
mysql> flush privileges;

设置默认编码为 utf8

mysql 安装后默认不支持中文,需要修改编码。
修改 /etc/my.cnf 配置文件,在相关节点(没有则自行添加)下添加编码配置,如下:

[mysqld]
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8

重启mysql服务,查询编码。可以看到已经改过来了

shell> systemctl restart mysqld
shell> mysql -uroot -p
mysql> show variables like 'character%';

查看编码

默认配置文件路径:

配置文件:/etc/my.cnf
日志文件:/var/log/var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid

原文地址:https://www.jianshu.com/p/1dab9a4d0d5f

Guess you like

Origin blog.csdn.net/w893932747/article/details/91823012