一、卸载默认安装的mariadb
[root@localhost ~]# yum remove mariadb* -y
二、添加mysql用户
[root@localhost ~]# useradd -s /sbin/nologin -M mysql
#-s 指定shell
#-M 不创建家目录
三、解压tar文件并移动到指定目录
[root@localhost ~]# tar zxvf mysql-5.7.-linux-glibc2.-x86_64.tar.gz
[root@localhost ~]# mv mysql-5.7.-linux-glibc2.-x86_64 mysql
[root@localhost ~]# mv mysql /usr/local/mysql
四、修改目录所属
[root@localhost ~]# chown -R mysql:mysql /usr/local/mysql/
五、初始化mysql
[root@localhost ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
--08T01::.343294Z [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
--08T01::.491621Z [Warning] InnoDB: New log files created, LSN=
--08T01::.530234Z [Warning] InnoDB: Creating foreign key constraint system tables.
--08T01::.587027Z [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.
--08T01::.588261Z [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
--08T01::.590350Z [Note] A temporary password is generated for root@localhost: 2op_Dr?L)klu
六、创建系统服务,并修改参数
[root@localhost ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# vi /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
#修改上边俩行参数,添加指定的mysql目录和数据目录
七、编辑配置文件
[root@localhost ~]# vi /etc/my.cnf
[mysqld]
user= mysql
port=
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
八、添加环境变量
[root@localhost ~]# vi .bash_profile
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin
#添加上边这行环境变量
[root@localhost ~]# source .bash_profile
九、启动mysql
[root@localhost ~]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
十、修改mysql密码及允许远程登录
[root@localhost ~]# mysql -uroot -p
Enter password: #密码为初始化时,自动生成的密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.7. Copyright (c) , , 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('');
Query OK, rows affected, 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 |
+-----------+---------------+
rows in set (0.00 sec) mysql> update user set host='%' where user='root';
Query OK, row affected (0.00 sec)
Rows matched: Changed: Warnings: mysql> flush privileges;
Query OK, rows affected (0.00 sec)
十一、添加系统服务及设置自启动
[root@localhost ~]# chkconfig --add mysqld
[root@localhost ~]# chkconfig --level mysqld on
注:记得关闭防火墙或者添加防火墙策略