数据库知多少系列-二进制安装mysql
数据库运维知多少系列-二进制安装mysql5.7版本
1、下载软件安装包
mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz
2、创建mysql用户
useradd mysql
passwd mysql 123456
创建用户使其不允许登录: 请注意要在root用户下进行
修改已经存在的用户使其不允许登录:
usermod -s /sbin/nologin <username >
新建用户不允许登录:
useradd -s /sbin/nologin <new username>
3、创建mysql5.7版本需要的目录
mkdir -pv /data/mysql/mysql9571/{conf,data,logs,run,tmp}
如果要安装多实例可以修改创建mysql9571目录名称
4、创建MySQL5.7需要的配置文件
[root@iZm5eckxl2tqyk76wy33pkZ ~]# cd /data/mysql/mysql9571/conf/
[root@iZm5eckxl2tqyk76wy33pkZ conf]# more my9571.cnf
[client]
default-character-set=utf8
port = 9571
socket = /data/mysql/mysql9571/run/mysql9571.sock
[mysqld]
user = mysql
port = 9571
character_set_server=utf8
init_connect='SET NAMES utf8'
socket = /data/mysql/mysql9571/run/mysql9571.sock
basedir = /opt/mysql-5.7.11-linux-glibc2.5-x86_64/
datadir = /data/mysql/mysql9571/data
log-error = /data/mysql/mysql9571/data/error.log
pid-file = /data/mysql/mysql9571/run/mysql9571.pid
tmpdir = /data/mysql/mysql9571/tmp
slow-query-log-file = /data/mysql/mysql9571/data/9571slow.log
log-bin = mysql-bin
binlog_format = row
server-id = 111
binlog-ignore-db = information_schema
binlog-ignore-db = cluster
binlog-ignore-db = mysql
binlog-do-db=test
[root@iZm5eckxl2tqyk76wy33pkZ conf]#
解压mysql二进制包
[root@VM_0_8_centos opt]# tar -zxvf mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz
修改目录权限
chown -R mysql.mysql /opt/mysql-5.7.11-linux-glibc2.5-x86_64/
chown -R mysql.mysql /data/mysql/mysql9571/
配置环境变量
echo 'export PATH=/opt/mysql-5.7.11-linux-glibc2.5-x86_64/bin:$PATH' >> /etc/profile
source /etc/profile
5、初始化mysql5.7版本数据库
[root@iZm5eckxl2tqyk76wy33pkZ conf]# cd /opt/mysql-5.7.11-linux-glibc2.5-x86_64/
[root@iZm5eckxl2tqyk76wy33pkZ mysql-5.7.11-linux-glibc2.5-x86_64]# ./bin/mysqld --initialize-insecure --user=mysql --basedir=/opt/mysql-5.7.11-linux-glibc2.5-x86_64 --datadir=/data/mysql/mysql9571/data/
2018-05-26T13:28:52.343461Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-05-26T13:28:53.463429Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-05-26T13:28:53.666121Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-05-26T13:28:53.738045Z 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: bbfcb5fa-60e8-11e8-bac6-00163e05510e.
2018-05-26T13:28:53.757450Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-05-26T13:28:53.757951Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
[root@iZm5eckxl2tqyk76wy33pkZ mysql-5.7.11-linux-glibc2.5-x86_64]# cd ~
查看my9571.cnf的权限
[root@ttlsa ~]# ls -l
my9571.cnf -rwxrwxrwx 1 root root 4878 Jul 30 11:31
my9571.cnf 权限777,任何一个用户都可以改my9571.cnf
存在很大的安全隐患.修复MySQL问题
[root@VM_0_8_centos conf]# chmod 644 my9571.cnf
6、启动mysql5.7版本数据库
[root@iZm5eckxl2tqyk76wy33pkZ mysql-5.7.11-linux-glibc2.5-x86_64]# ./bin/mysqld --defaults-file=/data/mysql/mysql9571/conf/my9571.cnf
[root@iZm5eckxl2tqyk76wy33pkZ conf]# cd /opt/mysql-5.7.11-linux-glibc2.5-x86_64/
注意这样不是后台进程启动,终端断开数据库会kill掉。
停止mysql的方法 :
[root@VM_0_2_centos logs]# mysqladmin -uroot -p shutdown -S /data/mysql/9571/run/mysql9571.sock
Enter password:
7、登陆数据库
[root@iZm5eckxl2tqyk76wy33pkZ mysql-5.7.11-linux-glibc2.5-x86_64]# ./bin/mysql -S /data/mysql/mysql9571/run/mysql9571.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.11-log MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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.00 sec)
mysql> exit
Bye
[root@iZm5eckxl2tqyk76wy33pkZ mysql-5.7.11-linux-glibc2.5-x86_64]# netstat -nltp
8、后台启动mysql
[root@iZm5eckxl2tqyk76wy33pkZ ~]# cd /opt/mysql-5.7.11-linux-glibc2.5-x86_64/
[root@iZm5eckxl2tqyk76wy33pkZ mysql-5.7.11-linux-glibc2.5-x86_64]# ./bin/mysqld --defaults-file=/data/mysql/mysql9571/conf/my9571.cnf &
[1] 2982
[root@iZm5eckxl2tqyk76wy33pkZ mysql-5.7.11-linux-glibc2.5-x86_64]#
9、修改root密码
修改后需要重启生效
[root@iZm5eckxl2tqyk76wy33pkZ mysql-5.7.11-linux-glibc2.5-x86_64]# ./bin/mysql -S /data/mysql/mysql9571/run/mysql9571.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.11-log MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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> update mysql.user set authentication_string=password('d7g91GzkR*ie%#o@') where user='root' and Host = 'localhost';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
flush privileges;
mysql> exit
Bye
[root@iZm5eckxl2tqyk76wy33pkZ mysql-5.7.11-linux-glibc2.5-x86_64]#
创建其他用户
mysql> grant all on *.* to 'test_db'@'%' identified by 'xiajing367300';
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> \q
Bye
[root@VM_0_8_centos mysql-5.7.11-linux-glibc2.5-x86_64]
10.修改后登陆
[root@iZm5eckxl2tqyk76wy33pkZ mysql-5.7.11-linux-glibc2.5-x86_64]# ./bin/mysql -uroot -p -S /data/mysql/mysql9571/run/mysql9571.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.11-log MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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> exit
Bye
[root@iZm5eckxl2tqyk76wy33pkZ mysql-5.7.11-linux-glibc2.5-x86_64]#