CentOS7 install MySQL 5.7

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.*-com"

MySQL installation using the command yum install installation

shell> yum install -y mysql-community-server

Start MySQL service

shell> systemctl start mysqld

View MySQL state with systemctl status

shell> systemctl status mysqld

Set boot

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

Changing the root password for local accounts

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

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

First need to set intensity level to verify the password, set global parameters can validate_password_policy is LOW,
the input setting values in the statement "set global validate_password_policy = LOW;" set value for

Setting password length, set the value of the input sentence "set global validate_password_length = 6;" set value for,

set password

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;

Add Telnet user

By default only allow the root account to log on locally, if you want to connect mysql on other machines, you must add an account to allow remote connections. Or modify the root to allow remote connections (not recommended)

Add an account to allow remote connections

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

Changing the root to allow remote connections (not recommended)

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

Setting default encoding is utf8

After mysql default installation does not support Chinese, we need to modify the code.
/Etc/my.cnf modify the configuration file (not then add their own) in the encoder configuration associated node is added, as follows:

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

Restart mysql service to check the encoding. We can see that change overnight

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

The default configuration file path:

  • Profile: /etc/my.cnf
  • Log Files: /var/log/var/log/mysqld.log
  • Service startup script: /usr/lib/systemd/system/mysqld.service
  • socket file: /var/run/mysqld/mysqld.pid

Guess you like

Origin www.cnblogs.com/xietianhua/p/11346083.html