Mysql 部署

#解压安装包
tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
#重命名为mysql
mv mysql-5.7.22-linux-glibc2.12-x86_64 mysql
#创建数据目录以及日志目录
mkdir -pv mysql/{data,logs}
#解压源码包创建日志文件
touch logs/mysql.log

vim /etc/my.cnf

#编辑配置文件

[mysqld]
datadir=/opt/mysql/data
socket=/tmp/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/opt/mysql/logs/mysql.log
pid-file=/opt/mysql/mysql.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

创建mysql用户

useradd mysql

更改属主跟组

chown -R mysql:mysql /opt/mysql

初始化数据库

/opt/mysql/bin/mysqld --initialize --user=mysql --basedir=/opt/mysql/ --datadir=/opt/mysql/data/
2018-12-03T14:25:44.988198Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2018-12-03T14:25:45.224949Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2018-12-03T14:25:45.289427Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2018-12-03T14:25:45.351773Z 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: 525de736-f707-11e8-a70e-000c29c9bb81.
    2018-12-03T14:25:45.352947Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2018-12-03T14:25:45.368198Z 1 [Note] A temporary password is generated for root@localhost: n5t&P;qJapsk

软连接

ln -s /opt/mysql/bin/mysql /usr/bin/mysql

编写shell启动

vim /opt/mysql/start.sh
#!/bin/bash
nohup /opt/mysql/bin/mysqld_safe --user=mysql --basedir=/opt/mysql/ --datadir=/opt/mysql/data/ &

授权

chmod +x /opt/mysql/start.sh

登录

mysql -uroot -p'n5t&P;qJapsk'

ERROR处理

[root@localhost mysql]# mysql -uroot -p'n5t&P;qJapsk'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
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.

修改用户密码

alter user 'root'@'localhost' identified by '123456';
[root@localhost mysql]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.22 MySQL Community Server (GPL)

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;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

mysql>

查询进程与端口

ps aux | grep mysql && netstat -tlnp | grep mysql
[root@localhost mysql]# ps aux | grep mysql && netstat -tlnp | grep mysql
root       6574  0.0  0.1 113472  1720 pts/2    S    09:35   0:00 /bin/sh /opt/mysql/bin/mysqld_safe --user=mysql --basedir=/opt/mysql/ --datadir=/opt/mysql/data/
mysql      6742  0.0 17.1 1117484 171808 pts/2  Sl   09:35   0:00 /opt/mysql/bin/mysqld --basedir=/opt/mysql/ --datadir=/opt/mysql/data --plugin-dir=/opt/mysql//lib/plugin --user=mysql --log-error=/opt/mysql/logs/mysql.log --pid-file=/opt/mysql/mysql.pid --socket=/tmp/mysql.sock
root       7189  0.0  0.0 112676   984 pts/2    R+   09:43   0:00 grep --color=auto mysql
tcp6       0      0 :::3306                 :::*                    LISTEN      6742/mysqld
文档更新时间: 2018-12-03 16:54   作者:RuM