您的位置:首页 > 运维架构 > Linux

linux环境下安装配置mysql 5.7.21

2018-03-15 16:02 531 查看
linux环境Mysql 5.7.21安装教程分享给大家,供大家参考,具体内容如下:

下载mysql:https://dev.mysql.com/downloads/mysql/


安装文件下载目录:/u01/software
Mysql目录安装位置:/usr/local/mysql
数据库保存位置:/u01/mysql
日志保存位置:/u01/log/mysql
1.准备目录,解压缩源文件到目标目录:[root@qht131 u01]# mkdir -p /u01/mysal
[root@qht131 u01]# mkdir -p /u01/log/mysql
[root@qht131 /]# mkdir -p /u01/software
[root@qht131 software]# cd /usr/local/mysql/
[root@qht131 mysql]# ls
bin  COPYING  docs  include  lib  man  README  share  support-files
[root@qht131 /]# cd /u01/software/
[root@qht131 software]# mv /home/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz /u01/software/
[root@qht131 software]# tar -zxvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz 
mysql-5.7.21-linux-glibc2.12-x86_64/bin/myisam_ftdump
mysql-5.7.21-linux-glibc2.12-x86_64/bin/myisamchk
mysql-5.7.21-linux-glibc2.12-x86_64/bin/myisamlog
mysql-5.7.21-linux-glibc2.12-x86_64/bin/myisampack
mysql-5.7.21-linux-glibc2.12-x86_64/bin/mysql
mysql-5.7.21-linux-glibc2.12-x86_64/bin/mysql_client_test_embedded
mysql-5.7.21-linux-glibc2.12-x86_64/bin/mysql_config_editor  。。
[root@qht131 software]# mv mysql-5.7.21-linux-glibc2.12-x86_64 /usr/local/mysql
[root@qht131 software]# cd /usr/local/mysql/
[root@qht131 mysql]# ls
bin COPYING docs include lib man README share support-files
2.新建mysql用户、组及目录[root@qht131 ~]# groupadd mysql
[root@qht131 ~]# useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql --新建mysql用户禁止shell登入
[root@qht131 ~]# chown -R mysql.mysql /u01
[root@qht131 ~]# chown -R mysql.mysql /usr/local/mysql
3.配置参数:[root@qht131 local]# cd /usr/local
[root@qht131 local]# ls
bin etc games include lib lib64 libexec mysql sbin share src
[root@qht131 local]# cd mysql/
[root@qht131 mysql]# ls
bin COPYING docs include lib man README share support-files
[root@qht131 mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/m
ysql --datadir=/u01/mysql
2018-03-15T14:11:44.365737Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-03-15T14:11:44.755078Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-03-15T14:11:44.844812Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-03-15T14:11:45.036216Z 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: cadbabe2-285a-11e8-ade3-000c295c63e0.
2018-03-15T14:11:45.038934Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-03-15T14:11:45.048939Z 1 [Note] A temporary password is generated for root@localhost: jZ:gu&X/=7#Z此处的密码需要记住,下面第一次登入的时候需要用到。[root@qht131 mysql]# bin/mysql_ssl_rsa_setup --datadir=/u01/mysql
Generating a 2048 bit RSA private key
............................+++
...........................................................+++
writing new private key to 'ca-key.pem'
-----
Generating a 2048 bit RSA private key
..............................+++
............................................................+++
writing new private key to 'server-key.pem'
-----
Generating a 2048 bit RSA private key
................................................+++
.........+++
writing new private key to 'client-key.pem'
-----
4.修改系统配置文件:[root@qht131 support-files]# cat /etc/my.cnf
[client]
port = 3306
socket = /u01/mysql/mysql.sock

[mysql]
no-auto-rehash

[mysqld]
socket = /usr/local/mysql/mysql.sock
character_set_server= utf8
init_connect= 'SET NAMES utf8'
basedir= /usr/local/mysql
datadir= /u01/mysql
socket = /u01/mysql/mysql.sock
log-error= /u01/log/mysql/mysql_3306.err
pid-file= /u01/mysql/mysqld.pid
lower_case_table_names = 1
sql_mode= STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

[mysqld_safe]
open-files-limit = 8192
log-error= /u01/log/mysql/mysql_3306.err
[root@qht131 support-files]# cp mysql.server /etc/init.d/mysql
[root@qht131 support-files]# vi /etc/init.d/mysql



5.启动mysql[root@qht131 mysql]# bin/mysqld_safe -user=mysql &
[1] 29796
[root@qht131 mysql]# 2018-03-15T15:41:56.637296Z mysqld_safe error: log-error set to '/u01/log/mysql/mysql_3306.err', however file don't exists. Create writable for user 'mysql'.

[1]+ Exit 1 bin/mysqld_safe -user=mysql
这里提示mysql_3306.err这个文件不存在,并且mysql用户无法建立。
只能手动建立并赋予权限了:[root@qht131 mysql]# touch /u01/log/mysql/mysql_3306.err
[root@qht131 mysql]# ll /u01/log/mysql/mysql_3306.err
-rw-r--r--. 1 root root 0 Mar 15 23:48 /u01/log/mysql/mysql_3306.err
[root@qht131 mysql]# chown mysql.mysql /u01/log/mysql/mysql_3306.err
[root@qht131 mysql]# bin/mysqld_safe -user=mysql &
[1] 30247
[root@qht131 mysql]# 2018-03-15T15:48:37.011645Z mysqld_safe Logging to '/u01/log/mysql/mysql_3306.err'.
2018-03-15T15:48:37.073643Z mysqld_safe Starting mysqld daemon with databases from /u01/mysql

6.连接mysql[root@qht131 mysql]# bin/mysql --user=root -p
Enter password: --输入第3步的密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.21

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>
mysql> set password=password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> use mysql
Database changed
mysql> select host,user from user;
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| localhost | mysql.session |
| localhost | mysql.sys     |
| localhost | root          |
+-----------+---------------+
3 rows in set (0.00 sec)

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.00 sec)

mysql> select host,user from user;
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| %         | root          |
| localhost | mysql.session |
| localhost | mysql.sys     |
| localhost | root          |
+-----------+---------------+
4 rows in set (0.00 sec)
7.添加系统路径,添加export PATH=/usr/local/mysql/bin:$PATH[root@qht131 mysql]# vi /etc/profile



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

8.设置mysql自动启动[root@qht131 mysql]# source /etc/profile
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql setup