mysql5.7安装

Posted 夜间独行的浪子

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql5.7安装相关的知识,希望对你有一定的参考价值。

整理一下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
[[email protected] 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
#报警告提示,使用如下方式初始化
[[email protected] 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
#初始化如下
[[email protected] 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
[[email protected] mysql]# service mysqld start
Starting MySQL.Logging to /data/mysql/test3.err.
 SUCCESS! 
#然后进入shell交互界面
[[email protected] 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>

新给定的临时密码是有一定的期限的,若过长时间不修改密码,再登录,则会出现如下错误!

[[email protected] 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.
[[email protected] mysql]#

这时候可以使用mysqladmin修改密码,如下:

[[email protected] 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.
[[email protected] mysql]#

 

以上是关于mysql5.7安装的主要内容,如果未能解决你的问题,请参考以下文章

CentOS7服务器中apachephp7以及mysql5.7的安装配置代码

shell脚本一键安装mysql5.7.x

Mysql5.7安装

mysql5.7.19 winx64解压缩版安装配置教程

MySql5.7安装及配置

Mysql5.7.12/10安装配置步骤