1、 系统环境、MySQL版本
系统是CentOS6.4,MySQL版本5.7.19
2、准备工作
2.1查看是否有自带的MySQL 库,如果先有卸载
[root@localhost mysql]# rpm -qa | grep mysql
mysql-libs-5.1.66-2.el6_3.x86_64
[root@localhost mysql]# rpm -e --nodeps mysql-libs-5.1.66-2.el6_3.x86_64
[root@localhost mysql]# rpm -qa | grep mysql
[root@localhost mysql]#
2.2下载MySQL rpm安装包
[root@localhost mysql]# wget --no-check-certificate https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.19-1.el6.x86_64.rpm-bundle.tar
3、MySQL安装
3.1进入下载目录,解压文件mysql-5.7.19-1.el6.x86_64.rpm-bundle.tar文件
[root@localhost mysql]# pwd
/soft/mysql
[root@localhost mysql]# tar -xf mysql-5.7.19-1.el6.x86_64.rpm-bundle.tar
[root@localhost mysql]# ll
total 922736
-rw-r--r--. 1 root root 472432640 Aug 23 00:47 mysql-5.7.19-1.el6.x86_64.rpm-bundle.tar
-rw-r--r--. 1 7155 31415 23618024 Jun 24 05:08 mysql-community-client-5.7.19-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 31415 336268 Jun 24 05:08 mysql-community-common-5.7.19-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 31415 3747580 Jun 24 05:08 mysql-community-devel-5.7.19-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 31415 39248236 Jun 24 05:08 mysql-community-embedded-5.7.19-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 31415 136599912 Jun 24 05:08 mysql-community-embedded-devel-5.7.19-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 31415 2177644 Jun 24 05:09 mysql-community-libs-5.7.19-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 31415 1723316 Jun 24 05:09 mysql-community-libs-compat-5.7.19-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 31415 159680896 Jun 24 05:09 mysql-community-server-5.7.19-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 31415 105292128 Jun 24 05:09 mysql-community-test-5.7.19-1.el6.x86_64.rpm
3.2安装文件
注:安装rpm文件要顺序执行
rpm -ivh mysql-community-common-5.7.19-1.el6.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.19-1.el6.x86_64.rpm
rpm -ivh mysql-community-client-5.7.19-1.el6.x86_64.rpm
rpm -ivh mysql-community-server-5.7.19-1.el6.x86_64.rpm
[root@localhost mysql]# rpm -ivh mysql-community-common-5.7.19-1.el6.x86_64.rpm
warning: mysql-community-common-5.7.19-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-common ########################################### [100%]
[root@localhost mysql]# rpm -ivh mysql-community-libs-5.7.19-1.el6.x86_64.rpm
warning: mysql-community-libs-5.7.19-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-libs ########################################### [100%]
[root@localhost mysql]# rpm -ivh mysql-community-c
mysql-community-client-5.7.19-1.el6.x86_64.rpm mysql-community-common-5.7.19-1.el6.x86_64.rpm
[root@localhost mysql]# rpm -ivh mysql-community-client-5.7.19-1.el6.x86_64.rpm
warning: mysql-community-client-5.7.19-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-client ########################################### [100%]
[root@localhost mysql]# rpm -ivh mysql-community-server-5.7.19-1.el6.x86_64.rpm
warning: mysql-community-server-5.7.19-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-server ########################################### [100%]
[root@localhost mysql]#
3.2 启动MySQL
[root@localhost mysql]# service mysqld start
Initializing MySQL database: [FAILED]
[root@localhost mysql]# service mysqld start
Starting mysqld: [ OK ]
第一次是初始化数据库 第二次就可以启动成功
3.3查找初始化密码登陆MySQL
MySQL安装完成后查看配置文件
[root@localhost 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@localhost mysql]#
其中数据库目录存放在了/var/lib/mysql下,日志文件存放在了/var/log/mysqld.log下
获取MySQL初始化密码并登陆,然后修改密码,就可以进行正常的数据库操作了。
[root@localhost mysql]# grep 'temporary password' /var/log/mysqld.log
2017-08-23T08:03:53.321124Z 1 [Note] A temporary password is generated for root@localhost: JQ3Ugfdw3b-G
[root@localhost mysql]# mysql -uroot -pJQ3Ugfdw3b-G
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 4
Server version: 5.7.19
Copyright (c) 2000, 2017, 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('123456');
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql>
4、遇到的问题及解决办法
4.1刚开始的时候rpm文件安装不上,主要是由于之前的MySQL关联文件没有删除干净。
解决办法:参考第一步方法可以解决。
4.2安装完成后登陆查看密码3.3可以查看
参考网址
http://www.linuxidc.com/Linux/2017-05/144363.htm
http://blog.youkuaiyun.com/liu_yulong/article/details/50328447
http://blog.youkuaiyun.com/t1anyuan/article/details/51858911