CentOS 7.2二进制安装mysql-5.7.19

时间:2022-11-05 11:39:42

官方文档地址:https://dev.mysql.com/doc/refman/5.7/en/binary-installation.html

开始安装

1、下载mysql二进制包

# cd /usr/local/src
# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz

2、下载mysql依赖的libaio 库

# yum search libaio
# yum install libaio

3、创建组和用户

# groupadd mysql
# useradd -r -g mysql -s /bin/false mysql

4、解压

# tar xf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz
# mv mysql-5.7.19-linux-glibc2.12-x86_64 /usr/local/mysql-5.7.19
# ln -s /usr/local/mysql-5.7.19/ /usr/local/mysql

5、配置环境变量

# export PATH=$PATH:/usr/local/mysql/bin
# echo "export PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile
# source /etc/profile

6、配置

# cd /usr/local/mysql
# mkdir mysql-files
# chown -R mysql.mysql mysql-files/
# chmod 750 mysql-files/
# ./bin/mysqld --initialize --user=mysql
# ./bin/mysql_ssl_rsa_setup 

7、创建必要目录

# mkdir /var/log/mariadb/
# touch /var/log/mariadb/mariadb.log
# chown -R mysql.mysql /var/log/mariadb/mariadb.log
# mkdir /var/run/mariadb/ -p
# touch /var/run/mariadb/mariadb.pid
# chown -R mysql.mysql /var/run/mariadb/

8、配置mysql启动脚本

# cp support-files/mysql.server /etc/init.d/mysqld
# chmod +x /etc/init.d/mysqld

9、启动mysql

# /etc/init.d/mysqld start

 

进入mysql并设置密码

1、在配置文件添加跳过授权表配置

[root@db01-36 ~]# head /etc/my.cnf
[mysqld]
skip-grant-tables        #在my.cnf配置键的[mysqld]下添加skip-grant-tables

2、重启mysql

/etc/init.d/mysqld restart 

3、进入mysql

mysql -S/var/lib/mysql/mysql.sock

4、进入后修改mysql密码

update mysql.user set authentication_string=password('新密码') where user='root' and Host = 'localhost';

5、退出mysql后,去掉/etc/my.cnf刚填加的跳过授权表配置

[root@db01-36 ~]# head /etc/my.cnf
[mysqld]
#skip-grant-tables          #删除或者用#号注释都可以

6、再次进入mysql

mysql -uroot -p新密码 -S/var/lib/mysql/mysql.sock

7、查看数据库

mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.          #查看数据库时报错

8、解决报错

mysql> set password for 'root'@'localhost'=password('新密码');       #新密码和前面设置的新密码要一致

9、此时在查看数据库

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
发现已经可以正常访问了!!!

再往后根据自身的需求作下数据库的优化就可以使用了!!!