Mysql 5.7安装

1. 下载安装文件到 /usr/local/src/


[root@honeybee ~]# cd /usr/local/src/
[root@honeybee src]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz

2. 创建安装目录、数据存放目录、日志目录


[root@honeybee src]# mkdir -p /usr/local/mysql
[root@honeybee src]# mkdir -p /data/mysql
[root@honeybee src]# mkdir -p /var/log/mysql

3. 解压压缩包到安装目录


[root@honeybee src]# tar -xzf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
[root@honeybee src]# mv mysql-5.7.20-linux-glibc2.12-x86_64/* /usr/local/mysql/

4. 创建mysql用户、组


[root@honeybee src]# cd /usr/local/mysql/
[root@honeybee mysql]# groupadd mysql
[root@honeybee mysql]# useradd -r -g mysql mysql


5. 设置目录权限


[root@honeybee mysql]# chown -R mysql /usr/local/mysql/
[root@honeybee mysql]# chown -R mysql:mysql /data/mysql
[root@honeybee mysql]# chgrp -R mysql /data/mysql
[root@honeybee mysql]# chown -R mysql:mysql /var/log/mysql

6. 初始化数据库


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

遇到如下错误:


[root@honeybee mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

安装libaio

[root@honeybee mysql]# yum install libaio

重新运行初始化


[root@honeybee mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
2017-11-12T14:06:27.150049Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-11-12T14:06:29.285338Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-11-12T14:06:29.516354Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-11-12T14:06:29.623677Z 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: ae0c4a8c-c7b2-11e7-a1cd-00163e102209.
2017-11-12T14:06:29.627181Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-11-12T14:06:29.627612Z 1 [Note] A temporary password is generated for root@localhost: rdCixlilG2*D

记住上面的初始密码:rdCixlilG2*D

7. 添加系统服务


[root@honeybee mysql]# cp -a ./support-files/mysql.server /etc/init.d/mysqld


8. 创建或修改/etc/my.cnf文件

my.cnf中关键配置:


[client]
port = 3306
socket=/tmp/mysql.sock
default-character-set=utf8
[mysqld]
basedir = /usr/local/mysql
datadir = /data/mysql
socket=/tmp/mysql.sock
pid-file = /data/mysql/mysql.pid
character_set_server=utf8
[mysqld_safe]
log-error = /var/log/mysql/error.log
pid-file = /data/mysql/mysql.pid

9. 启动mysql


[root@honeybee mysql]# service mysqld start
Starting MySQL.                                            [  OK  ]

10. 登录、更改密码


[root@honeybee mysql]# bin/mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.20-log

Copyright (c) 2000, 2017, 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)

11. 为root用户添加远程连接的能力


mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> select host,user,authentication_string from mysql.user;
+-----------+---------------+-------------------------------------------+
| host      | user          | authentication_string                     |
+-----------+---------------+-------------------------------------------+
| localhost | root          | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| localhost | mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| localhost | mysql.sys     | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| %         | root          | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+---------------+-------------------------------------------+
4 rows in set (0.00 sec)

12. 添加环境变量

修改 /etc/profile文件


PATH=$PATH:/usr/local/mysql/bin

使修改立即生效


[root@honeybee mysql]# source /etc/profile

13. 忘记密码时,可用如下方法重置:



[root@honeybee mysql]# /usr/local/mysql/bin/mysqld_safe --user=root --skip-grant-tables --skip-networking &

[root@honeybee mysql]# mysql -uroot

mysql> use mysql;

mysql> update user set authentication_string=password('123456') where user='root';

mysql> flush privileges;


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 5.7和之前版本的MySQL有一些不同,现把CentOS 7下MySQL 5.7安装、配置与应用完整过程记下来,或...
    alterem阅读 3,584评论 0 0
  • 方式一:通过Yum进行安装 1、先查看系统上是否已经安装了自带的MySQL 如果系统有安装,那可以选择进行卸载: ...
    喵咪家De喻少爷阅读 2,405评论 0 0
  • 1.下载mysql源安装包 2.安装mysql源 3.检查mysql源是否安装成功 4.出现类似这样的就OK了 5...
    JackSpeed阅读 3,919评论 0 1
  • 初始化方式Window 64: 1.修改my-default.ini名称 ==> my.ini 2.初始化数据文件...
    Herman7z阅读 2,481评论 0 0
  • 做一缕秋风般的女子,携一抹思念对南飞的大雁道一声:珍重!带一丝微笑,对飘飞的冬雪说一声:你早! 做一缕秋风般的...
    虫虫欲懂阅读 1,774评论 0 1