1.先下载tar包安装放入linux 目录,然后解压并移动到/usr/local/mysql目录下
tar -zxvf mysql-5.6.44-linux-glibc2.12-x86_64.tar.gz mv mysql-5.6.44-linux-glibc2.12-x86_64.tar.gz msyql mv mysql /usr/local/
2.创建mysql组和用户
# 创建mysql用户组[root@VMTest ~]# groupadd mysql# 创建一个用户名为mysql的用户,并加入mysql用户组[root@VMTest ~]# useradd -g mysql mysql
3.更改所属的组和用户
# 更改所属的组和用户[root@VMTest local]# chown -R mysql mysql/[root@VMTest local]# chgrp -R mysql mysql/[root@VMTest local]# cd mysql/[root@VMTest mysql]# mkdir data[root@VMTest mysql]# chown -R mysql:mysql data
4.在/etc下创建my.cnf文件
# 进入/etc文件夹下[root@VMTest mysql]# cd /etc# 创建my.cnf文件[root@VMTest etc]# touch my.cnf# 编辑my.cnf[root@VMTest etc]# vim my.cnf
5.my.cnf添加如下内容
[mysql] # 设置mysql客户端默认字符集default-character-set=utf8 [mysqld] # 设置3306端口port =3306# 设置mysql的安装目录basedir=/usr/local/mysql # 设置mysql数据库的数据的存放目录datadir=/usr/local/mysql/data # 允许最大连接数max_connections=200# 服务端使用的字符集默认为8比特编码的latin1字符集character-set-server=utf8 # 创建新表时将使用的默认存储引擎default-storage-engine=INNODB lower_case_table_names=1max_allowed_packet=16M # 表不区分大小写lower_case_table_names=1user = mysql tmpdir = /tmp [mysqld_safe] log-error = /usr/local/mysql/data/error.log pid-file = /usr/local/mysql/data/mysql.pid
6.初始化mysql
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/mysql.pid --tmpdir=/tmp
7.启动mysql
# 启动mysql[root@VMTest mysql]# /etc/init.d/mysqld start
8.设置开机启动
#设置开机启动[root@VMTest mysql]# chkconfig --level 35 mysqld on[root@VMTest mysql]# chkconfig --list mysqld[root@VMTest mysql]# chmod +x /etc/rc.d/init.d/mysqld[root@VMTest mysql]# chkconfig --add mysqld[root@VMTest mysql]# chkconfig --list mysqld[root@VMTest mysql]# service mysqld statusSUCCESS! MySQL running (4475)
9.配置变量
# 进入/etc/profile文件夹[root@VMTest mysql]# vim /etc/profile# 修改/etc/profile文件#set mysql environmentexportPATH=$PATH:/usr/local/mysql/bin # 使文件生效[root@VMTest mysql]# source /etc/profile
10.获得mysql初始密码
# 1、获得mysql初始密码[root@VMTest bin]# cat /root/.mysql_secret# Password set for user 'root@localhost' at 2017-04-17 17:40:02_pB*3VZl5T<6 # 2、修改密码[root@VMTest bin]# mysql -uroot -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 53Server version: 5.7.22 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. mysql> set PASSWORD = PASSWORD('root'); Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec)
11.添加远程访问权限
# 添加远程访问权限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 -ADatabase changed mysql> update user sethost='%' where user='root'; Query OK, 0 rows affected (0.00 sec) Rows matched: 1 Changed: 0 Warnings: 0mysql> select host,user from user; +-----------+---------------+| host | user | +-----------+---------------+| % | root | | localhost | mysql.session | | localhost | mysql.sys | +-----------+---------------+3 rows inset (0.00 sec)
12.重启mysql生效
# 重启mysql[root@VMTest bin]# /etc/init.d/mysqld restartShutting down MySQL.. Starting MySQL.