mysql进阶
Posted liuzhenchao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql进阶相关的知识,希望对你有一定的参考价值。
1. 二进制格式mysql安装
//下载二进制格式的mysql软件包
[root@20liuzhenchao ~]# cd /usr/local/
[root@localhost src]# wget [[email protected] local]# wget https://downloads.mysql.com/archives/get/file/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
--2019-04-29 19:58:07-- https://downloads.mysql.com/archives/get/file/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
正在解析主机 downloads.mysql.com (downloads.mysql.com)... 137.254.60.14
正在连接 downloads.mysql.com (downloads.mysql.com)|137.254.60.14|:443... 已连接。
100%[++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=====================================>] 643,790,848 4.55MB/s 用时 30s
2019-04-29 21:24:36 (5.19 MB/s) - 已保存 “mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz” [643790848/643790848])
//创建用户和组
[root@20liuzhenchao local]# groupadd -r mysql
[root@20liuzhenchao local]# useradd -M -s /sbin/nologin -g mysql mysql
//解压软件至/usr/local/
[root@20liuzhenchao local]# tar -xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
[root@20liuzhenchao local]# ln -sv mysql-5.7.22-linux-glibc2.12-x86_64 mysql
"mysql" -> "mysql-5.7.22-linux-glibc2.12-x86_64"
[root@20liuzhenchao local]# ll
总用量 628704
drwxr-xr-x. 2 root root 6 12月 15 2017 bin
drwxr-xr-x. 2 root root 6 12月 15 2017 etc
drwxr-xr-x. 2 root root 6 12月 15 2017 games
drwxr-xr-x. 2 root root 6 12月 15 2017 include
drwxr-xr-x. 2 root root 6 12月 15 2017 lib
drwxr-xr-x. 2 root root 6 12月 15 2017 lib64
drwxr-xr-x. 2 root root 6 12月 15 2017 libexec
lrwxrwxrwx. 1 root root 35 4月 29 22:24 mysql -> mysql-5.7.22-linux-glibc2.12-x86_64
drwxr-xr-x. 9 root root 129 4月 29 22:05 mysql-5.7.22-linux-glibc2.12-x86_64
-rw-r--r--. 1 root root 643790848 3月 4 2018 mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
drwxr-xr-x. 2 root root 6 12月 15 2017 sbin
drwxr-xr-x. 5 root root 49 4月 28 23:15 share
drwxr-xr-x. 2 root root 6 12月 15 2017 src
//修改目录/usr/local/mysql的属主属组
[root@20liuzhenchao local]# chown -R mysql.mysql mysql-5.7.22-linux-glibc2.12-x86_64
[root@20liuzhenchao mysql]# ll -d
drwxr-xr-x. 9 mysql mysql 129 4月 29 22:05 .
//添加环境变量
[root@20liuzhenchao mysql]# ls
bin COPYING docs include lib man README share support-files
[root@20liuzhenchao mysql]# echo ‘export PATH=/usr/local/mysql/bin:$PATH‘ > /etc/profile.d/mysql.sh
[root@20liuzhenchao mysql]# . /etc/profile.d/mysql.sh
[root@20liuzhenchao mysql]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
//建立数据存放目录
[root@20liuzhenchao mysql]# mkdir /opt/data
[root@20liuzhenchao mysql]# chown -R mysql.mysql /opt/data
[root@20liuzhenchao mysql]# ll /opt/data -d
drwxr-xr-x. 2 mysql mysql 6 4月 29 22:57 /opt/data
//初始化数据库
[root@20liuzhenchao mysql]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
2019-04-29T15:00:39.845522Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-04-29T15:00:40.456817Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-04-29T15:00:40.630171Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-04-29T15:00:40.750603Z 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: 8e0ba300-6a8f-11e9-9b37-000c29fc116c.
2019-04-29T15:00:40.752085Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed‘ cannot be opened.
2019-04-29T15:00:40.754098Z 1 [Note] A temporary password is generated for root@localhost: 6ojuoTdt&de!
//请注意,这个命令的最后会生成一个临时密码,此处密码是6ojuoTdt&de!
//生成配置文件
[root@20liuzhenchao ~]# cat > /etc/my.cnf <<EOF
> [mysqld]
> basedir = /usr/local/mysql
> datadir = /opt/data
> socket = /tmp/mysql.sock
> port = 3306
> pid-file = /opt/data/mysql.pid
> user = mysql
> skip-name-resolve
> EOF
[root@20liuzhenchao mysql]# cat /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve
//配置服务启动脚本
[root@20liuzhenchao ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@20liuzhenchao ~]# sed -ri ‘s#^(basedir=).*#\1/usr/local/mysql#g‘ /etc/init.d/mysqld
[root@20liuzhenchao ~]# sed -ri ‘s#^(datadir=).*#\1/opt/data#g‘ /etc/init.d/mysqld
//启动mysql
[root@20liuzhenchao ~]# /etc/init.d/mysqld start
Starting MySQL.Logging to ‘/opt/data/20liuzhenchao.err‘.
. SUCCESS!
[root@20liuzhenchao ~]# ps -ef |grep mysql
root 2221