Creating user groups and users
[root @ localhost Software] # groupadd MySQL groupadd: "mysql" group already exists [root @ localhost Software] # useradd - G MySQL MySQL useradd: user "mysql" already exists [root @ localhost Software] # [root @ localhost Software] # passwd mysql to change the user's password mysql. The new password: Invalid Password: The password is a palindrome re-enter the new password:
Extracting installation package
[root@localhost software]# tar -zxvf mysql-5.7.26-el7-x86_64.tar.gz
After extracting the file folder to move
[root@localhost software]# mv mysql-5.7.26-el7-x86_64/ /usr/local/mysql
Change the group and user belongs
[root@localhost mysql]# cd /home/mysql/ [root@localhost mysql]# chown -R mysql mysql/ [root@localhost mysql]# chgrp -R mysql mysql/ [root@localhost mysql]# mkdir data [root@localhost mysql]# chown -R mysql:mysql data
installation
[root@localhost mysql]# cd /usr/local/mysql/ [root@localhost mysql]# bin/mysql_install_db --user=mysql --datadir=/home/mysql/data/ 2019-07-19 11:02:18 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize 2019-07-19 11:02:20 [WARNING] The bootstrap log isn't empty: 2019-07-19 11:02:20 [WARNING] 2019-07-19T03:02:18.443343Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead 2019-07-19T03:02:18.443888Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000) 2019-07-19T03:02:18.443892Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
And set the directory permissions
[root @ localhost MySQL] # cp ./support-files/mysql.server /etc/init.d/ MySQL [root @ localhost etc] # vi my.cnf modify the configuration file [root @ localhost etc] # chown 777 My. CNF [the root @ localhost etc] # the chmod + X /etc/init.d/mysql
Set boot
[root @ localhost etc] # --level the chkconfig 35 MySQL ON [root @ localhost etc] # the chkconfig - List MySQL MySQL 0 : Off 1 : Off 2 : opening 3 : On 4 : opening 5 : opening 6 : Off [root @localhost etc] #
Modify the configuration file
[root @ localhost /] # vi / etc / Profile modify / etc / Profile, add the following in the last # modify / etc / Profile file #set MySQL Environment Export the PATH = $ the PATH: / usr / local / MySQL / bin # make file take effect [root @ localhost /] # Source / etc / Profile [root @ localhost /] #
Obtaining initial password mysql
[root@localhost /]# cat /root/.mysql_secret # Password set for user 'root@localhost' at 2019-07-19 11:02:18 Pkz:zkdpy50q [root@localhost /]#
change Password
[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.26-log 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('root'); Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) mysql> exit Bye
Add Remote Access
[root@localhost /]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.26-log MySQL Community Server (GPL) 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> 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> update user set host='%' where user='root'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select host,user from user; +-----------+---------------+ | host | user | +-----------+---------------+ | % | root | | localhost | mysql.session | | localhost | mysql.sys | +-----------+---------------+ 3 rows in set (0.00 sec) mysql>
Mysql restart to take effect
[root@localhost /]# service mysql stop Shutting down MySQL.. SUCCESS! [root@localhost /]# service mysql start Starting MySQL... SUCCESS! [root@localhost /]# service mysql status SUCCESS! MySQL running (46983) [root@localhost /]#
Open ports
firewall-cmd --permanent --zone=public --add-port=3306/tcp //永久 [root@localhost /]# firewall-cmd --permanent --zone=public --add-port=3306/tcp success [root@localhost /]# firewall-cmd --reload success [root@localhost /]#