1.这里我将mysql安装在/usr/local/mysql目录里面,也可以安装在其他地方
mkdir /usr/local/mysql
2.下载mysql压缩包
wget http://dev.MySQL.com/get/Downloads/MySQL-5.7/mysql-5.7.11-Linux-glibc2.5-x86_64.tar.gz
3.解压并复制
tar -xvf mysql-5.7.11-Linux-glibc2.5-x86_64.tar.gz
mv mysql-5.7.11-Linux-glibc2.5-x86_64/* /usr/local/mysql/
4.创建data目录
mkdir /usr/local/mysql/data
5.创建mysql用户和修改权限
groupadd mysql
chown -R mysql.mysql /usr/local/mysql/
6.初始化数据(进入/usr/local/mysql,文件目录下)执行
./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
7. 复制配置文件到 /etc/my.cnf
cp -a ./support-files/my-default.cnf /etc/my.cnf (选择y)
8. mysql的服务脚本放到系统服务中
cp -a ./support-files/mysql.server /etc/init.d/mysqld
9.修改my.cnf文件
vim /etc/my.cnf
修改如下:(阿里云记用专用网络,记得把安全组的端口3306打开)
[mysqld]
skip-grant-tables #(加入这个是为了安装的号不用密码登录去重置mysql密码,重置好密码后,删除)
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
bind-address = 0.0.0.0 #(是为了Navicat连接mysql)
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
# server_id = .....
socket = /tmp/mysql.sock
character-set-server = utf8
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
10.启动mysql
service mysqld start
11.重置mysql密码(CentOS 6 之后password字段改成authentication_string字段),刷新有效并退出
[root@localhost mysql]# mysql -u root mysql
mysql> update mysql.user set authentication_string=password('123456') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 2 Changed: 1 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
[root@xxxx /]#
12.创建快捷方式
ln -s /usr/local/mysql/bin/mysql /usr/bin
13.重启mysql
/etc/init.d/mysql restart
14.登录mysql
mysql -u root -p