1、准备用户
[root@centos79-mysql03 ~]# groupadd -r mysql
[root@centos79-mysql03 ~]# useradd -r -g mysql mysql
[root@centos79-mysql03 ~]# id mysql
2、准备数据目录,建议使用逻辑卷
[root@centos79-mysql03 ~]# mkdir -p /data/mysql
[root@centos79-mysql03 ~]# chown mysql:mysql /data/mysql
3、准备二进制程序
[root@centos79-mysql03 ~]# wget https://mirrors.aliyun.com/mysql/MySQL-5.6/mysql-5.6.51-linux-glibc2.12-x86_64.tar.gz
[root@centos79-mysql03 ~]# tar xf mysql-5.6.51-linux-glibc2.12-x86_64.tar.gz -C /usr/local
[root@centos79-mysql03 ~]# cd /usr/local
[root@centos79-mysql03 local]# ln -sv mysql-5.6.51-linux-glibc2.12-x86_64 mysql
[root@centos79-mysql03 local]# ll
total 0
drwxr-xr-x. 2 root root 6 Apr 11 2018 bin
drwxr-xr-x. 2 root root 6 Apr 11 2018 etc
drwxr-xr-x. 2 root root 6 Apr 11 2018 games
drwxr-xr-x. 2 root root 6 Apr 11 2018 include
drwxr-xr-x. 2 root root 6 Apr 11 2018 lib
drwxr-xr-x. 2 root root 6 Apr 11 2018 lib64
drwxr-xr-x. 2 root root 6 Apr 11 2018 libexec
lrwxrwxrwx 1 root root 35 Nov 15 17:24 mysql -> mysql-5.6.51-linux-glibc2.12-x86_64
[root@centos79-mysql03 local]# chown -R root:root /usr/local/mysql/
4、准备配置文件
[root@centos79-mysql03 local]# cd /usr/local/mysql/
[root@centos79-mysql03 mysql]# cp -b support-files/my-default.cnf /etc/my.cnf
[root@centos79-mysql03 mysql]# vim /etc/my.cnf
# mysql语句块中添加以下三个选项
[mysqld]
datadir = /data/mysql
innodb_file_per_table = on #在5.5以上版的是默认值,可不加
skip_name_resolve = on #禁止主机名解析,建议使用
5、创建数据库文件
[root@centos79-mysql03 ~]# yum install -y autoconf
[root@centos79-mysql03 mysql]# ./scripts/mysql_install_db --datadir=/data/mysql --user=mysql
[root@centos79-mysql03 ~]# ll /data/mysql/
total 110600
-rw-rw---- 1 mysql mysql 12582912 Nov 15 17:33 ibdata1
-rw-rw---- 1 mysql mysql 50331648 Nov 15 17:33 ib_logfile0
-rw-rw---- 1 mysql mysql 50331648 Nov 15 17:33 ib_logfile1
drwx------ 2 mysql mysql 4096 Nov 15 17:33 mysql
drwx------ 2 mysql mysql 4096 Nov 15 17:33 performance_schema
drwx------ 2 mysql mysql 6 Nov 15 17:33 test
6、准备服务脚本,并启动服务
[root@centos79-mysql03 ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@centos79-mysql03 ~]# chkconfig --add mysqld
[root@centos79-mysql03 ~]# service mysqld start
Starting MySQL.Logging to '/data/mysql/centos79-mysql03.err'.
. SUCCESS!
7、PATH路径
[root@centos79-mysql03 ~]# echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@centos79-mysql03 ~]# . /etc/profile.d/mysql.sh
8、安全初始化
# 运行脚本:mysql_secure_installation
设置数据库管理员root口令
禁止root远程登录
删除anonymous用户帐号
删除test数据库
# 针对MySQL5.6前版本进行安全加固
[root@centos79-mysql03 ~]# /usr/local/mysql/bin/mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
... Success!
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Cleaning up...
9、登录数据库
[root@centos79-mysql03 ~]# mysql -uroot -pRoot123!
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 13
Server version: 5.6.51 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, 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> status
--------------
mysql Ver 14.14 Distrib 5.6.51, for linux-glibc2.12 (x86_64) using EditLine wrapper
Connection id: 13
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.6.51 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /tmp/mysql.sock
Uptime: 6 min 17 sec
Threads: 1 Questions: 40 Slow queries: 0 Opens: 68 Flush tables: 1 Open tables: 61 Queries per second avg: 0.106
--------------
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END