安装环境:centos6
###1、下载
###2、解压缩到/usr/local/
[root@localhost local]# cd /usr/local/soft/
[root@localhost soft]# tar zvxf mysql-5.7.10-linux-glibc2.5-i686.tar.gz -C /usr/local
[root@localhost soft]# cd ..
[root@localhost local]# mv /usr/local/mysql-5.7.10-linux-glibc2.5-i686 /usr/local/mysql
###3、在mysql下面创建data数据库文件目录
[root@localhost local]# mkdir /usr/local/mysql/data
###4、创建mysql的用户组和用户,并对mysql目录设置用户组和用户
[root@localhost local]# groupadd mysql
[root@localhost local]# useradd mysql -g mysql
[root@localhost local]# cd mysql
[root@localhost mysql]# pwd
/usr/local/mysql
[root@localhost mysql]# chown -R mysql .
[root@localhost mysql]# chgrp -R mysql .
###5、初始化mysql并启动mysql服务
[root@localhost mysql]# cd /usr/local/mysql/bin
[root@localhost bin]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2016-01-09 12:00:28 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2016-01-09 12:00:33 [WARNING] The bootstrap log isn't empty:
2016-01-09 12:00:33 [WARNING] 2016-01-09T04:00:29.262989Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
2016-01-09T04:00:29.264643Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2016-01-09T04:00:29.264653Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
报警可以忽略
###6、修改my.cnf
[root@localhost mysql]# vim /etc/my.cnf
# 将datadir=/var/lib/mysql修改为实际的安装路径 如 datadir=/usr/local/mysql/data
[root@localhost mysql]# vim /etc/selinux/config
# 把SELINUX=enforcing改为SELINUX=disabled后存盘退出重启机器
###7、创建sock文件目录
[root@localhost mysql]# mkdir -p /var/lib/mysql
[root@localhost mysql]# chown mysql:mysql /var/lib/mysql
###8、 建立sock文件软连接
[root@localhost bin]# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
###9、启动mysql
[root@localhost bin]# cd /usr/local/mysql/support-files
[root@localhost support-files]# ./mysql.server start
###10、配置mysql环境变量
[root@localhost bin]# vim /etc/profile
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin
###11、获取mysql初始化密码,登录mysql,修改密码
[root@localhost ~]# cat /root/.mysql_secret
[root@localhost ~]# cd /usr/local/mysql/bin
[root@localhost bin]# ./mysql -uroot -p:5ul#d6dkcwX
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.10
Copyright (c) 2000, 2015, 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>
###12、改mysql的root密码,新密码在此为’root’
mysql> set password=password('root');
Query OK, 0 rows affected, 1 warning (0.00 sec)
###13、设定远程登录mysql。在Linux下为了安全,默认是不允许mysql本机以外的机器访问mysql数据库服务,因此需要重新授权root。
mysql> grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
grant all privileges on *.* to 'root’@'centos1' identified by 'root' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
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
mysql> select Host,User from user;
+-----------+-----------+
| Host | User |
+-----------+-----------+
| % | root |
| localhost | mysql.sys |
| localhost | root |
+-----------+-----------+
3 rows in set (0.00 sec)
###14、将mysql配置到服务并设置开机启动
[root@centos1 mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@centos1 mysql]# chkconfig mysql on
[root@centos1 mysql]# service mysql start
###15、报错解决
[root@centos1 mysql]# service iptables stop
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
[root@centos1 mysql]# service iptables status
iptables: Firewall is not running.
mkdir -p /var/lib/mysql
chown mysql:mysql /var/lib/mysql
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock