创建用户组和用户
[root@localhost software]# groupadd mysqlgroupadd:“mysql”组已存在[root@localhost software]# useradd -g mysql mysqluseradd:用户“mysql”已存在[root@localhost software]# [root@localhost software]# passwd mysql更改用户 mysql 的密码 。新的 密码:无效的密码: 密码是一个回文重新输入新的 密码:
解压安装包
[root@localhost software]# tar -zxvf mysql-5.7.26-el7-x86_64.tar.gz
移动解压后的文件夹
[root@localhost software]# mv mysql-5.7.26-el7-x86_64/ /usr/local/mysql
更改所属的组和用户
[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
安装
[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 --initialize2019-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 instead2019-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)
设置目录及权限
[root@localhost mysql]# cp ./support-files/mysql.server /etc/init.d/mysql[root@localhost etc]# vi my.cnf修改配置文件[root@localhost etc]# chown 777 my.cnf[root@localhost etc]# chmod +x /etc/init.d/mysql
设置开机启动
[root@localhost etc]# chkconfig --level 35 mysql on[root@localhost etc]# chkconfig --list mysqlmysql 0:关 1:关 2:开 3:开 4:开 5:开 6:关[root@localhost etc]#
修改配置文件
[root@localhost /]# vi /etc/profile修改/etc/profile,在最后添加如下内容# 修改/etc/profile文件#set mysql environmentexport PATH=$PATH:/usr/local/mysql/bin#使文件生效[root@localhost /]# source /etc/profile[root@localhost /]#
获得mysql初始密码
[root@localhost /]# cat /root/.mysql_secret# Password set for user ‘root@localhost‘ at 2019-07-19 11:02:18 Pkz:zkdpy50q[root@localhost /]#
修改密码
[root@localhost /]# mysql -uroot -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.7.26-logCopyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.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> exitBye
添加远程访问权限
[root@localhost /]# mysql -uroot -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 4Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql> use mysqlReading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> update user set host=‘%‘ where user=‘root‘;Query OK, 1 row affected (0.00 sec)Rows matched: 1 Changed: 1 Warnings: 0mysql> select host,user from user;+-----------+---------------+| host | user |+-----------+---------------+| % | root || localhost | mysql.session || localhost | mysql.sys |+-----------+---------------+3 rows in set (0.00 sec)mysql>
重启mysql生效
[root@localhost /]# service mysql stopShutting down MySQL.. SUCCESS! [root@localhost /]# service mysql startStarting MySQL... SUCCESS! [root@localhost /]# service mysql status SUCCESS! MySQL running (46983)[root@localhost /]#
打开端口
firewall-cmd --permanent --zone=public --add-port=3306/tcp //永久[root@localhost /]# firewall-cmd --permanent --zone=public --add-port=3306/tcpsuccess[root@localhost /]# firewall-cmd --reloadsuccess[root@localhost /]#