1.mysql-5.7.25-1.el6.x86_64.rpm-bundle.tar下载百度云资源
提取码:ej1y
2.把下载的mysql安装包上传到Centos上
解压mysql,我这是在Windows上解压的上传到Centos上,我在Centos上解压mysql不知道为什么少了rpm -ivh mysql-community-common-5.7.25-1.el6.x86_64.rpm包
tar –xvf mysql-5.7.25-1.el6.x86_64.rpm-bundle.tar
3.查看mysql依赖
rpm -qa | grep mysql
4.如果查看有mysql依赖,就删除mysql依赖,
rpm -e --nodeps `rpm -qa | grep mysql`
5.再次查是否有mysql依赖
rpm -qa | grep mysql
6.安装一定要按照顺序来
第一个安装: rpm -ivh mysql-community-common-5.7.25-1.el6.x86_64.rpm报了一个错误
[root@localhost mysql-5.7.25]# rpm -ivh mysql-community-common-5.7.25-1.el6.x86_64.rpm
warning: mysql-community-common-5.7.25-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
file /usr/share/mysql/charsets/Index.xml from install of mysql-community-common-5.7.25-1.el6.x86_64 conflicts with file from package MariaDB-common-10.4.8-1.el7.centos.x86_64
file /usr/share/mysql/charsets/armscii8.xml from install of mysql-community-common-5.7.25-1.el6.x86_64 conflicts with file from package MariaDB-common-10.4.8-1.el7.centos.x86_64
file /usr/share/mysql/charsets/ascii.xml from install of mysql-community-common-5.7.25-1.el6.x86_64 conflicts with file from package MariaDB-common-10.4.8-1.el7.centos.x86_64
file /usr/share/mysql/charsets/cp1250.xml from install of mysql-community-common-5.7.25-1.el6.x86_64 conflicts with file from package MariaDB-common-10.4.8-1.el7.centos.x86_64
file /usr/share/mysql/charsets/cp1251.xml from install of mysql-community-common-5.7.25-1.el6.x86_64 conflicts with file from package MariaDB-common-10.4.8-1.el7.centos.x86_64
file /usr/share/mysql/charsets/cp1256.xml from install of mysql-community-common-5.7.25-1.el6.x86_64 conflicts with file from package MariaDB-common-10.4.8-1.el7.centos.x86_64
file /usr/share/mysql/charsets/cp1257.xml from install of mysql-community-common-5.7.25-1.el6.x86_64 conflicts with file from package MariaDB-common-10.4.8-1.el7.centos.x86_64
file /usr/share/mysql/charsets/cp850.xml from install of mysql-community-common-5.7.25-1.el6.x86_64 conflicts with file from package MariaDB-common-10.4.8-1.el7.centos.x86_64
file /usr/share/mysql/charsets/cp852.xml from install of mysql-community-common-5.7.25-1.el6.x86_64 conflicts with file from package MariaDB-common-10.4.8-1.el7.centos.x86_64
file /usr/share/mysql/charsets/cp866.xml from install of mysql-community-common-5.7.25-1.el6.x86_64 conflicts with file from package MariaDB-common-10.4.8-1.el7.centos.x86_64
file /usr/share/mysql/charsets/dec8.xml from install of mysql-community-common-5.7.25-1.el6.x86_64 conflicts with file from package MariaDB-common-10.4.8-1.el7.centos.x86_64
file /usr/share/mysql/charsets/geostd8.xml from install of mysql-community-common-5.7.25-1.el6.x86_64 conflicts with file from package MariaDB-common-10.4.8-1.el7.centos.x86_64
file /usr/share/mysql/charsets/greek.xml from install of mysql-community-common-5.7.25-1.el6.x86_64 conflicts with file from package MariaDB-common-10.4.8-1.el7.centos.x86_64
file /usr/share/mysql/charsets/hebrew.xml from install of mysql-community-common-5.7.25-1.el6.x86_64 conflicts with file from package MariaDB-common-10.4.8-1.el7.centos.x86_64
file /usr/share/mysql/charsets/hp8.xml from install of mysql-community-common-5.7.25-1.el6.x86_64 conflicts with file from package MariaDB-common-10.4.8-1.el7.centos.x86_64
file /usr/share/mysql/charsets/keybcs2.xml from install of mysql-community-common-5.7.25-1.el6.x86_64 conflicts with file from package MariaDB-common-10.4.8-1.el7.centos.x86_64
file /usr/share/mysql/charsets/koi8r.xml from install of mysql-community-common-5.7.25-1.el6.x86_64 conflicts with file from package MariaDB-common-10.4.8-1.el7.centos.x86_64
file /usr/share/mysql/charsets/koi8u.xml from install of mysql-community-common-5.7.25-1.el6.x86_64 conflicts with file from package MariaDB-common-10.4.8-1.el7.centos.x86_64
file /usr/share/mysql/charsets/latin1.xml from install of mysql-community-common-5.7.25-1.el6.x86_64 conflicts with file from package MariaDB-common-10.4.8-1.el7.centos.x86_64
file /usr/share/mysql/charsets/latin2.xml from install of mysql-community-common-5.7.25-1.el6.x86_64 conflicts with file from package MariaDB-common-10.4.8-1.el7.centos.x86_64
file /usr/share/mysql/charsets/latin5.xml from install of mysql-community-common-5.7.25-1.el6.x86_64 conflicts with file from package MariaDB-common-10.4.8-1.el7.centos.x86_64
file /usr/share/mysql/charsets/latin7.xml from install of mysql-community-common-5.7.25-1.el6.x86_64 conflicts with file from package MariaDB-common-10.4.8-1.el7.centos.x86_64
file /usr/share/mysql/charsets/macce.xml from install of mysql-community-common-5.7.25-1.el6.x86_64 conflicts with file from package MariaDB-common-10.4.8-1.el7.centos.x86_64
file /usr/share/mysql/charsets/macroman.xml from install of mysql-community-common-5.7.25-1.el6.x86_64 conflicts with file from package MariaDB-common-10.4.8-1.el7.centos.x86_64
file /usr/share/mysql/charsets/swe7.xml from install of mysql-community-common-5.7.25-1.el6.x86_64 conflicts with file from package MariaDB-common-10.4.8-1.el7.centos.x86_64
[root@localhost mysql-5.7.25]# file /usr/share/mysql/charsets/Index.xml from install of mysql-community-common-5.7.25-1.el6.x86_64 conflicts with file from package MariaDB-common-10.4.8-1.el7.centos.x86_64
/usr/share/mysql/charsets/Index.xml: XML document text
from: cannot open `from' (No such file or directory)
install: cannot open `install' (No such file or directory)
of: cannot open `of' (No such file or directory)
mysql-community-common-5.7.25-1.el6.x86_64: cannot open `mysql-community-common-5.7.25-1.el6.x86_64' (No such file or directory)
conflicts: cannot open `conflicts' (No such file or directory)
with: cannot open `with' (No such file or directory)
file: cannot open `file' (No such file or directory)
from: cannot open `from' (No such file or directory)
package: cannot open `package' (No such file or directory)
MariaDB-common-10.4.8-1.el7.centos.x86_64: cannot open `MariaDB-common-10.4.8-1.el7.centos.x86_64' (No such file or directory)
原因:已存在MariaDB-common-10.4.8-1.el7.centos.x86_64的库(这是我以前安装MariaDB数据库,如果是别的也要根据对应的名字删除),所以需要先删除以前的库才能安装!
执行强制卸载命令:
rpm -e MariaDB-common-10.4.8-1.el7.centos.x86_64--nodeps
然后查看:
rpm –qa | grep mysql
再继续安装
rpm -ivh mysql-community-common-5.7.25-1.el6.x86_64.rpm
[root@localhost mysql-5.7.25]# rpm -ivh mysql-community-common-5.7.25-1.el6.x86_64.rpm
warning: mysql-community-common-5.7.25-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-common ########################################### [100%]
第二个安装:
rpm -ivh mysql-community-libs-5.7.25-1.el6.x86_64.rpm
[root@localhost mysql-5.7.25]# rpm -ivh mysql-community-libs-5.7.25-1.el6.x86_64.rpm
warning: mysql-community-libs-5.7.25-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-libs ########################################### [100%]
第三个安装
rpm -ivh mysql-community-client-5.7.25-1.el6.x86_64.rpm
[root@localhost mysql-5.7.25]# rpm -ivh mysql-community-client-5.7.25-1.el6.x86_64.rpm
warning: mysql-community-client-5.7.25-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-client ########################################### [100%]
第四个安装
rpm -ivh mysql-community-server-5.7.25-1.el6.x86_64.rpm
[root@localhost mysql-5.7.25]# rpm -ivh mysql-community-server-5.7.25-1.el6.x86_64.rpm
warning: mysql-community-server-5.7.25-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-server ########################################### [100%]
You have new mail in /var/spool/mail/root
第五个安装
rpm -ivh mysql-community-devel-5.7.25-1.el6.x86_64.rpm
[root@localhost mysql-5.7.25]# rpm -ivh mysql-community-devel-5.7.25-1.el6.x86_64.rpm
warning: mysql-community-devel-5.7.25-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-devel ########################################### [100%]
7.使用命令启动mysql服务
service mysqld start
[root@localhost mysql-5.7.25]# service mysqld start
Starting mysqld: [ OK ]
[root@localhost mysql-5.7.25]#
8.使用命令生成一个随机密码:grep "temporary password" /var/log/mysqld.log
[root@localhost mysql-5.7.25]# grep "temporary password" /var/log/mysqld.log
2020-04-07T12:32:39.276158Z 1 [Note] A temporary password is generated for root@localhost: >v>uyo:fg7.O
[root@localhost mysql-5.7.25]#
注意:密码是root@localhost:右边的字符串
root@localhost: >v>uyo:fg7.O 这里生成的随机密码是:>v>uyo:fg7.O
MySQL 会在 /var/log/mysqld.log 日志中生成一个随机密码,默认需要修改密码才能使用
可以通过 vim /var/log/mysqld.log 打开里面有一行这样的代码
2020-04-07T12:32:39.276158Z 1 [Note] A temporary password is generated for root@localhost: >v>uyo:fg7.O
9.修改密码,先登录mysql
mysql -u root –p
[root@localhost mysql-5.7.25]# mysql -u root -p
Enter password:
我这随机密码就是:>v>uyo:fg7.O
10.登录成功
[root@localhost log]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.7.25
Copyright (c) 2000, 2019, 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> ALTER USER 'root'@'localhost' IDENTIFIED BY 'wangqing';
Query OK, 0 rows affected (0.01 sec)
mysql>
11.修改密码:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
12.设置权限
为了可以远程连接该数据库,需要设置相应的权限
#任何主机
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '刚刚修改的密码' WITH GRANT OPTION;
#指定主机
mysql>GRANT ALL PRIVILEGES ON *.* TO 'xxxx'@’xx.xx.xx.xx’ IDENTIFIED BY 'xxxx' WITH GRANT OPTION;
13.刷新权限
mysql>flush privileges;
这就完成了,可以用sql工具连接mysql了