CentOS 6.8
mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz
mysql安装步骤:
1. 增加新系统用户mysql,设置新密码
[root@node1 ~]# adduser mysql [root@node1 ~]# passwd mysql2. 解压mysql安装包
[root@node1 mysql]# tar -zxvf mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz [root@node1 mysql]# ll total 320868 drwxr-xr-x. 13 root root 4096 Sep 24 11:09 mysql-5.6.40-linux-glibc2.12-x86_64 -rw-r--r--. 1 root root 328563044 May 9 2018 mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz
3. 更改安装目录名称,更改目录所有者
[root@node1 mysql]# mv mysql-5.6.40-linux-glibc2.12-x86_64 mysql [root@node1 mysql]# ll total 320868 drwxr-xr-x. 13 root root 4096 Sep 24 11:35 mysql -rw-r--r--. 1 root root 328563044 May 9 2018 mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz [root@node1 mysql]# chown -R mysql.mysql mysql [root@node1 mysql]# ll total 320868 drwxr-xr-x. 13 mysql mysql 4096 Sep 24 11:35 mysql -rw-r--r--. 1 root root 328563044 May 9 2018 mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz
4. 创建数据文件保存目录,更改目录所有者
[root@node1 mysql]# mkdir data [root@node1 mysql]# chown -R mysql.mysql data [root@node1 mysql]# ll total 320872 drwxr-xr-x. 2 mysql mysql 4096 Sep 24 11:11 data drwxr-xr-x. 13 mysql mysql 4096 Sep 24 11:09 mysql -rw-r--r--. 1 root root 328563044 May 9 2018 mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz
5. 安装mysql
[root@node1 mysql]# cd mysql [root@node1 mysql]# pwd /home/mysql/mysql [root@node1 mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/home/mysql/mysql --datadir=/home/mysql/data/
6. 更换系统默认/etc/my.cnf文件
[root@node1 mysql]# cp support-files/my-default.cnf /etc/my.cnf cp: overwrite `/etc/my.cnf'? y [root@node1 mysql]#
7. 编辑/etc/my.cnf
basedir = /home/mysql/mysql datadir = /home/mysql/data port = 3306 # server_id = ..... socket = /tmp/mysql.sock log-err = /home/mysql/data/error.log pid-file = /home/mysql/data/mysql.pid
8. 将mysql的启动服务添加到系统服务中
[root@node1 mysql]# cp support-files/mysql.server /etc/init.d/mysql
9. 启动mysql
[root@node1 mysql]# service mysql start Starting MySQL.Logging to '/home/mysql/data/node1.miselehe.com.err'. ... [ OK ]
10. 设置环境变量
[root@node1 mysql]# vim /root/.bash_profile PATH=$PATH:$HOME/bin:/home/mysql/mysql/bin:/home/mysql/mysql/lib使修改生效
[root@node1 mysql]# source /root/.bash_profile
11. 开机启动项
[root@node1 mysql]# chkconfig --add mysql [root@node1 mysql]# chkconfig --list | grep mysql mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
12. 链接客户端
[root@node1 mysql]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.6.40 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. # 可以使用root远程链接 mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "123456"; Query OK, 0 rows affected (0.00 sec) # 更换到mysql 数据库 mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed # 设置root密码 mysql> update user set Password = password('123456') where User='root'; Query OK, 4 rows affected (0.01 sec) Rows matched: 5 Changed: 4 Warnings: 0 # 使设置生效 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
13. 修改防火墙设置
[root@node1 mysql]# vim /etc/sysconfig/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT重启防火墙
[root@node1 mysql]# service iptables restart iptables: Setting chains to policy ACCEPT: filter [ OK ] iptables: Flushing firewall rules: [ OK ] iptables: Unloading modules: [ OK ] iptables: Applying firewall rules: [ OK ]