centos7 安装mysql5.7(二进制安装)
一、卸载默认安装的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.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
四、修改目录所属
[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 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
六、创建系统服务,并修改参数
[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= 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
八、添加环境变量
[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 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)
十一、添加系统服务及设置自启动
[root@localhost ~]# chkconfig --add mysqld [root@localhost ~]# chkconfig --level 35 mysqld on
注:记得关闭防火墙或者添加防火墙策略