MySQL-5.7.20 installation configuration

1) Download the installation package: https://pan.baidu.com/s/17dyNFbfU2QZhRKvQjjgitw

 2) Check whether mysql has been installed under the Linux you are using, and whether it has been uninstalled cleanly

rpm -qa|grep -i mysql

mysql-5.7.13-linux-glibc2.5-x86_64

 

If the library file is already installed, it should be uninstalled first, otherwise an overwrite error will occur. Note the uninstall: the --nodeps option was used when uninstalling, ignoring dependencies:

rpm -e mysql-5.7.13-linux-glibc2.5-x86_64 --nodeps

 

Of course, you may have more than one file, and there may be more than one file. Then you uninstall it in sequence with rpm -e xx --nodeps. After uninstalling, check it again. If you are sure that it is deleted, go to the following steps.

Find the directory of the previous version of mysql, and delete the files and libraries of the old version of mysql:

find / -name mysql

 

If the relevant directory is found, use "rm -rf directory address" to delete, such as:

rm -rf /var/lib/mysql
rm -rf /var/lib/mysql/mysql
rm -rf /var/spool/mail/mysql
rm -rf /usr/lib64/mysql
rm -rf /usr/share/mysql

 

3) Unzip the installation package and install it

unzip MySQL-5.7.20.zip
cd MySQL-5.7.20
rpm -ivh mysql-community-common-5.7.20-1.el6.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.20-1.el6.x86_64.rpm --force
rpm -ivh mysql-community-client-5.7.20-1.el6.x86_64.rpm --force
rpm -ivh mysql-community-server-5.7.20-1.el6.x86_64.rpm --force

 

4) Create mysql user and user group

userdel mysql # delete user
groupadd mysql
useradd -g mysql mysql -s /bin/false #Create user mysql and add it to the mysql group, mysql users are not allowed to log in directly to the system
chown -R mysql:mysql /var #Set MySQL database storage directory permissions
chown -R mysql:mysql /usr #Set MySQL database storage directory permissions

 

5) Execute mysqld --initialize --user=mysql

 

6) Modify the initial password

Enter the log file to find the password generated by initialization

vi /var/log/mysqld.log
  Find something like this:
A temporary password is generated for root@localhost: x8Ka2oY:D48v

"x8Ka2oY:D48v" is the initial password.

 

start mysql

service mysqld start

 

log in to mysql

mysql -uroot -p

Enter the initial password in Enter password: and press Enter

 

Execute sql to change the password

mysql>set password=password('test2018');
mysql>flush privileges;
mysql>exit;

 

restart mysql 

service mysqld restart

 

7) Modify the /etc/my.cnf configuration file

vim /etc/my.cnf
 The replacement content is as follows:
[mysqld]
datadir = / var / lib / mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
symbolic-links=0
default-time-zone = '+8:00'
lower_case_table_names=1
log_bin_trust_function_creators=1
key_buffer_size = 384M
max_allowed_packet = 50M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
skip-name-resolve
user = mysql
log-bin=mysql-bin
server-id = 1
character_set_server = utf8
[mysqldump]
quick
max_allowed_packet = 50M

[mysql]
no-auto-rehash
default-character-set = utf8

[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout

[client]
default-character-set = utf8

Restart mysql service mysqld restart to complete.

 

8) Start/restart/stop the mysql service

service mysqld start # start the service
service mysqld restart # restart the service
service mysqld stop # stop the service

 

9) Change some encoding

mysql>use mysql
mysql>show variables like 'character%';
mysql>SET character_set_database = utf8;

 

10) mysql remote authorization

mysql> grant all privileges on . to 'root'@'%' identified by 'test2018';

Installed!

 

11) Database initialization

Log in:

mysql -u root -ptest2018

Create the database:

create database test2018 default charset=utf8;

Exit: exit;

Initialization data:

mysql -uroot -ptest2018 --default-character-set=utf8 mastersp< /home/test2018.sql

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326072148&siteId=291194637