linux安装mysql5.7及相关环境配置

安装mysql5.7以及相关环境配置

检查是否自带mysql和mariadb,并卸载

rpm -qa|grep mysql   //rpm -e --nodeps mysql-libs-5.1.52-1.el6_0.1.x86_64

[root@localhost ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64

//卸载
[root@localhost ~]# rpm -e --nodeps mysql-libs-5.1.52-1.el6_0.1.x86_64
[root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64

下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads

选择版本后下载,然后上传到服务器解压

解压:

tar -xzvf mysql....tar.gz

移动并重命名mysql

[root@localhost ~]# mv mysql-5.7.32-linux-glibc2.12-x86_64 /usr/local/mysql-5.7.32

创建用户组

[root@localhost mysql-5.7.32]# groupadd mysql
[root@localhost mysql-5.7.32]# useradd -r -g mysql mysql
[root@localhost mysql-5.7.32]# chown -R mysql:mysql /usr/local/mysql-5.7.32/

添加mysql服务:

cp /usr/local/mysql-5.7.29/support-files/mysql.server /etc/init.d/mysql

修改/etc/init.d/mysql

basedir=/usr/local/mysql-5.7.32
datadir=/usr/local/mysql-5.7.32/data

创建my_default.conf
路径:/usr/local/mysql-5.7.32/support-files

[mysqld]

#设置mysql的安装目录
basedir = /usr/local/mysql-5.7.32
#设置mysql数据库的数据存放目录
datadir = /usr/local/mysql-5.7.32/data
#设置端口
port = 3306

explicit_defaults_for_timestamp=true

socket = /tmp/mysql.sock
#设置字符集
character-set-server=utf8
#日志存放目录
log-error = /usr/local/mysql-5.7.32/data/mysqld.log
pid-file = /usr/local/mysql-5.7.32/data/mysqld.pid
#允许时间类型的数据为零(去掉NO_ZERO_IN_DATE,NO_ZERO_DATE)
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
#ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

然后把my_default.conf文件复制并该文件名为/etc/my.cnf

sql_mode:

STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

初始配置

[root@localhost mysql-5.7.32]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql-5.7.32/ --datadir=/usr/local/mysql-5.7.32/data/

查看日志:

[root@localhost data]# cat mysqld.log 
2020-11-13T05:02:37.425129Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-11-13T05:02:37.488867Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-11-13T05:02:37.556845Z 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: 72f9cbb2-256d-11eb-8976-000c29c5f1de.
2020-11-13T05:02:37.557795Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-11-13T05:02:38.304828Z 0 [Warning] CA certificate ca.pem is self signed.
2020-11-13T05:02:38.485332Z 1 [Note] A temporary password is generated for root@localhost: TPFUIjwa+4T-
[root@localhost data]# pwd
/usr/local/mysql-5.7.32/data

把启动脚本放到开机初始化目录

cp support-files/mysql.server /etc/init.d/mysql

启动mysql

[root@localhost init.d]# service mysql start
Starting MySQL. SUCCESS! 

修改mysql5.7 root密码:

已知密码:

[root@localhost mysql-5.7.32]# ./bin/mysql -uroot -p

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

不修改密码的话会报错,必须先修改密码:alter user 'root'@'localhost' identified by 'poiuzxcv0987';
mysql> use mysql
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> update user set authentication_string=password('poiuzxcv0987') where user='root';
ERROR 1046 (3D000): No database selected
mysql> use mysql;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> update mysql.user set authentication_string=password('poiuzxcv0987') where user='root';
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user 'root'@'localhost' identified by 'poiuzxcv0987';

在修改密码过程中,如果密码过于简单也会报错的,我们可以修改:`validate_password_length` (密码长度)参数默认为8,我们修改为1
validate_password_policy:参数0表示长度验证,参数1或者medium·表示大写或小写和特殊字符。,参数2或者STRONG,表示长度,大写或者小写和特殊字符,文件名称
默认是1,即MEDIUM,所以要求,带线密码长度必须符合长度,含数字和小写或者大写

set global validate_password_policy=0;
// 设置密码长度为1
set global validate_password_length=1;

修改密码:

mysql> alter user 'root'@'localhost' identified by 'poiuzxcv0987';

posted @ 2020-11-13 10:40  蝶墨轩冕  阅读(586)  评论(0编辑  收藏  举报