centos7 installation mysql5.7 (binary installation)

First, uninstall mariadb installed by default

[root@localhost ~]# yum remove mariadb* -y

 

Second, add a mysql user

[root @ localhost ~] # useradd -s / sbin / nologin - M MySQL 
# - S specifies the shell 
# -M do not create home directories

 

Third, extract the tar file and move it to the specified directory

[root@localhost ~]# tar zxvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz 
[root@localhost ~]# mv mysql-5.7.25-linux-glibc2.12-x86_64 mysql
[root@localhost ~]# mv mysql /usr/local/mysql

 

Fourth, modify the directory belongs

[root@localhost ~]# chown -R mysql:mysql /usr/local/mysql/

 

V. initialization mysql

[root@localhost ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2019-08-08T01:26:04.343294Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-08-08T01:26:04.491621Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-08-08T01:26:04.530234Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-08-08T01:26:04.587027Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 7d4db01d-b97b-11e9-8ac2-000c290afcba.
2019-08-08T01:26:04.588261Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-08-08T01:26:04.590350Z 1 [Note] A temporary password is generated for root@localhost: 2op_Dr?L)klu 

 

Sixth, create a system service, and modify parameters

[the root @ localhost ~] # CP /usr/local/mysql/support-files/mysql.server /etc/init.d/ mysqld 
[the root @ localhost ~] # VI /etc/init.d/ mysqld 
the basedir = / usr / local / mysql 
DATADIR = / usr / local / mysql / data 
# modify both the top line parameters, and add the specified directory data directory mysql

 

Seven, edit the configuration file

[root@localhost ~]# vi /etc/my.cnf 
[mysqld]
user= mysql
port= 3306
socket=/tmp/mysql.sock
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
log-error=/usr/local/mysql/data/mysql.log
pid-file=/usr/local/mysql/data/mysql.pid
character-set-server=utf8
collation-server=utf8_bin

 

Eight, adding environment variables

[root @ localhost ~] # vi .bash_profile 
the PATH = $ the PATH: $ the HOME / bin: / usr / local / MySQL / bin 
# added on top of this line environment variables
[root @ localhost ~] # source  .bash_profile

 

Nine, start mysql

[root@localhost ~]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS! 

 

Ten, modify mysql password and allow remote login

[root@localhost ~]# 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.25

Copyright (c) 2000, 2019, 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> set password=password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

mysql> select host,user from user; 
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| localhost | mysql.session |
| localhost | mysql.sys     |
| localhost | root          |
+-----------+---------------+
3 rows in set (0.00 sec)

mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

 

XI, added system services and settings from the start

[root@localhost ~]# chkconfig --add mysqld
[root@localhost ~]# chkconfig --level 35 mysqld on

 

Note: Remember to turn off the firewall or add a firewall policy

Guess you like

Origin www.cnblogs.com/yyxianren/p/11319544.html