整理一下mysql5.7的安装,安装基本与之前的mysql5.6保持一致,但是会有一些不同,来介绍一下!
整理一下安装mysql的步骤,大致如下:
- 解压压缩包(二进制免编译压缩包)
- 修改压缩包名字
- 创建mysql用户和用户组(组也可以不创建)
- 创建datadir目录
- 初始化数据库
- 修改启动脚本文件,5.7.22版本好像没有默认配置文件。
- 启动mysql
安装过程如下:
#解压文件包 tar zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz #修改文件包名字并移动位置 mv mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql #创建mysql用户 useradd -M mysql #创建数据库目录 mkdir /data/mysql #修改mysql目录的用户主和用户组 chown -R mysql:mysql /data/mysql #安装mysql [root@test3 mysql]# ./bin/mysql_install_db --user=mysql --datadir=/data/mysql 2018-07-18 19:21:28 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize #报警告提示,使用如下方式初始化 [root@test3 mysql]# ./bin/mysqld --initialize --user=mysql --datadir=/data/mysql ./bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory #安装时报错,可以使用安装如下文件包 yum -y install numactl.x86_64 #初始化如下 [root@test3 mysql]# ./bin/mysqld --initialize --user=mysql --datadir=/data/mysql 2018-07-18T11:24:17.639719Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2018-07-18T11:24:18.757337Z 0 [Warning] InnoDB: New log files created, LSN=45790 2018-07-18T11:24:18.939043Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2018-07-18T11:24:19.007577Z 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: 1c981b1a-8a7d-11e8-98d1-fa336351fc00. 2018-07-18T11:24:19.009188Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2018-07-18T11:24:19.010028Z 1 [Note] A temporary password is generated for root@localhost: ASB=D_(8zN?d #注意最后一行,有一个临时密码设置 #拷贝启动脚本 cp -p support-files/mysql.server /etc/init.d/mysqld #修改mysqld文件 sed -i "s/^datadir=/datadir=/data/mysql/" /etc/init.d/mysqld #启动mysql [root@test3 mysql]# service mysqld start Starting MySQL.Logging to '/data/mysql/test3.err'. SUCCESS! #然后进入shell交互界面 [root@test3 mysql]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 3 Server version: 5.7.22 Copyright (c) 2000, 2018, 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>show databases; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. #mysql5.7要求必须更改密码,然后才可以正常使用。 mysql> alter user "root"@"localhost" identified by "123qwE#!"; Query OK, 0 rows affected (0.00 sec) #mysql已经可以正常使用 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec) mysql>
新给定的临时密码是有一定的期限的,若过长时间不修改密码,再登录,则会出现如下错误!
[root@test1 mysql]# mysql -uroot -p Enter password: ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords. [root@test1 mysql]#
这时候可以使用mysqladmin修改密码,如下:
[root@test1 mysql]# ./bin/mysqladmin -uroot -p password Enter password: New password: Confirm new password: Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety. [root@test1 mysql]#
在初始化的时候,若是不想mysql自己设置密码,可以使用参数--initialize-inscure来初始化。
mysqld --initialize-insecure --datadir=/data/mysql --user=mysql
需要注意一点的是,mysql5.7在安装时会自动在/etc/my.cnf下创建配置文件,因此不需要再拷贝,但是需要修改数据库文件中目录位置,配置文件如下:
[mysqld] datadir=/data/mysql socket=/data/mysql/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 [mysqld_safe] log-error=/data/mysql/test.log pid-file=/var/run/mysqld/mysqld.pid
mysql5.7的安装脚本如下:
#!/bin/bash #mysql5.7安装脚本 mysql_v=mysql-5.7.23-linux-glibc2.12-x86_64 print_str() { echo -e "