安装环境:
Linux系统:Centos6.5
第一步:根据操作系统版本下载数据库:
CentOS_6下载:mysql-5.7.22-1.el6.x86_64.rpm-bundle.tar
CentOS_7下载:mysql-5.7.17-1.el7.x86_64.rpm-bundle.tar
下载地址:https://dev.mysql.com/downloads/mysql/
第二步:删除系统自带的mysql数据库
1.rpm -qa | grep mysql
2.rpm -e mysql-libs-5.1.71-1.el6.x86_64 --nodeps
第三步:解压tar包,然后上传到服务器中
上传后如下:
第四步:按照顺序解压
- rpm -ivh mysql-community-libs-5.7.24-1.el6.x86_64.rpm --nodeps --force
[[email protected] mysql]# rpm -ivh mysql-community-libs-5.7.24-1.el6.x86_64.rpm --nodeps --force
warning: mysql-community-libs-5.7.24-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-libs ########################################### [100%]
[[email protected] mysql]#
- rpm -ivh mysql-community-devel-5.7.24-1.el6.x86_64.rpm --nodeps --force
[[email protected] mysql]# rpm -ivh mysql-community-devel-5.7.24-1.el6.x86_64.rpm --nodeps --force
warning: mysql-community-devel-5.7.24-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-devel ########################################### [100%]
[[email protected] mysql]#
- rpm -ivh mysql-community-client-5.7.24-1.el6.x86_64.rpm --nodeps --force
[[email protected] mysql]# rpm -ivh mysql-community-client-5.7.24-1.el6.x86_64.rpm --nodeps --force
warning: mysql-community-client-5.7.24-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-client ########################################### [100%]
[[email protected] mysql]#
- rpm -ivh mysql-community-server-5.7.24-1.el6.x86_64.rpm --nodeps --force
[[email protected] mysql]# rpm -ivh mysql-community-server-5.7.24-1.el6.x86_64.rpm --nodeps --force
warning: mysql-community-server-5.7.24-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-server ########################################### [100%]
[[email protected] mysql]#
- rpm -ivh mysql-community-common-5.7.24-1.el6.x86_64.rpm --nodeps --force
[[email protected] mysql]# rpm -ivh mysql-community-common-5.7.24-1.el6.x86_64.rpm --nodeps --force
warning: mysql-community-common-5.7.24-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-common ########################################### [100%]
[[email protected] mysql]#
第五步:启动mysql
service mysqld start
[[email protected] mysql]# service mysqld start
Starting mysqld: [ OK ]
mysql
[[email protected] mysql]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
报错:因为没有输入账号密码,可以选择免密码登录
解决方案: vi /etc/my.cnf
[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
skip-grant-tables
在最后加上 skip-grant-tables
然后重启 :/etc/init.d/mysqld restart
[[email protected] mysql]# /etc/init.d/mysqld restart
Stopping mysqld: [ OK ]
Starting mysqld: [ OK ]
最后在进mysql:
[[email protected] mysql]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.24 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>
然后修改密码,修改用户权限可以让数据库可以远程连接:
mysql> update mysql.user set authentication_string=password('138922') where user='root' ;
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> use mysql;
Database changed
mysql> select Host, User from user;
+-----------+---------------+
| Host | User |
+-----------+---------------+
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+---------------+
3 rows in set (0.00 sec)
mysql> update user set host = '%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
修改完成后,在去 vi /etc/my.cnf,把刚才加的那一行 skip-grant-tables去掉!!!
大功告成!!