[root@slaver2 ~]# cat /etc/redhat-release
CentOS release 6.8 (Final)
##查看是否安装
[root@slaver2 ~]# rpm -qa | grep mysql
mysql-libs-5.1.73-8.el6_8.x86_64
##如果安装进行卸载
[root@slaver2 ~]# rpm -e mysql
error: package mysql is not installed
[root@slaver2 ~]# rpm -e --nodeps mysql
error: package mysql is not installed
##如果没有安装,把包进行移除
[root@slaver2 ~]# yum -y remove mysql-libs
我本地已经把mysql-5.7.17-1.el6.x86_64.rpm-bundle.tar下载好了,没有的可以登录到官网进行下载。用WinScp软件上传到Centos服务器上。
##查看包中的文件
[root@slaver2 mycloud]# tar -tf mysql-5.7.17-1.el6.x86_64.rpm-bundle.tar
mysql-community-test-5.7.17-1.el6.x86_64.rpm
mysql-community-embedded-5.7.17-1.el6.x86_64.rpm
mysql-community-embedded-devel-5.7.17-1.el6.x86_64.rpm
mysql-community-server-5.7.17-1.el6.x86_64.rpm
mysql-community-libs-compat-5.7.17-1.el6.x86_64.rpm
mysql-community-devel-5.7.17-1.el6.x86_64.rpm
mysql-community-client-5.7.17-1.el6.x86_64.rpm
mysql-community-libs-5.7.17-1.el6.x86_64.rpm
mysql-community-common-5.7.17-1.el6.x86_64.rpm
##解压到Mysql文件夹下
[root@slaver2 mycloud]# tar -xf mysql-5.7.17-1.el6.x86_64.rpm-bundle.tar -C ./mysql
[root@slaver2 mysql]# groupadd -r mysql
[root@slaver2 mysql]# useradd -r -g mysql -s /bin/false -M mysql
##安装依赖包
rpm -ivh mysql-community-common-5.7.17-1.el6.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.17-1.el6.x86_64.rpm
##安装客户端
rpm -ivh mysql-community-client-5.7.17-1.el6.x86_64.rpm
##安装服务端
rpm -ivh mysql-community-server-5.7.17-1.el6.x86_64.rpm
mysql安装完成后,需要初始化root 用户获得初始密码
[root@slaver2 mysql]# mysqld --initialize --user=mysql
临时密码存在mysql.log内容下
[root@slaver2 mysql]# cat /var/log/mysqld.log |grep password
2017-05-03T06:11:50.136597Z 1 [Note] A temporary password is generated for root@localhost: ie8su.rjFCp:
启动mysql服务
[root@slaver2 mysql]# /etc/init.d/mysqld status
mysqld is stopped
[root@slaver2 mysql]# /etc/init.d/mysqld start
Starting mysqld: [ OK ]
[root@slaver2 mysql]# mysql -uroot -pie8su.rjFCp:
mysql> alter user 'root'@'localhost' identified by '123456';
mysql> exit
mysql> mysql -uroot -p
Enter password:
mysql> show databases; +--------------------+
| Database | +--------------------+
| information_schema | | mysql | | performance_schema |
| sys | +--------------------+
4 rows in set (0.00 sec)
mysql>
设置MySQL开机自启动
##查看是否开启
[root@slaver2 mysql]# chkconfig --list |grep mysql
mysqld 0:off 1:off 2:off 3:on 4:on 5:on 6:off
##如果没开启,执行语句
[root@slaver2 mysql]# chkconfig --level 345 mysqld on
到此处mysql已经安装完成,mysq配置文件my.cnf
具体配置信息
[root@slaver2 mysql]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# 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
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# 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
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[root@slaver2 mysql]#
参考文章:http://blog.csdn.net/u012456926/article/details/50166287