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 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 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
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>
8.设置mysql自动启动[root@qht131 mysql]# source /etc/profile
下载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/mysql3.配置参数:[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
相关文章推荐
- Linux 安装与配置 mysql 环境
- LAMP攻略: LAMP环境搭建,Linux下Apache,MySQL,PHP安装与配置
- linux 下安装python+django+mysql配置环境
- Linux 环境配置之 安装 Mysql
- Linux 安装与配置 mysql 环境
- Linux下安装配置nginx+php+mysql环境
- linux环境下mysql5.6的安装、配置、使用及常见问题解决办法
- window环境配置Mysql 5.7.21 windowx64.zip免安装版教程详解
- Linux 安装与配置 mysql 环境
- Linux开发环境搭建之MySQL安装配置
- Linux 安装与配置 mysql 环境
- linux下mysql的安装以及环境变量的配置
- Windows 环境下 MySQL 5.7.21 安装配置
- Linux环境配置(三)——通过.rpm安装MySQL
- LAMP攻略: LAMP环境搭建,Linux下Apache,MySQL,PHP安装与配置
- Linux(CentOS)环境下MySQL的安装、配置与使用
- linux环境mysql的安装主从关系的配置
- linux 下安装 mysql 并配置 python 开发环境
- 【centos6.5】CentOS 6.5系统安装配置LAMP(Apache+PHP5+MySQL)服务器环境(linux公社)
- Linux(CentOS6.x)下使用yum软件管理工具安装LNMP(Nginx+PHP+Mysql)环境并配置虚拟主机vhost