1.安装wget命令(如果有忽略)
[root@localhost ZL]# yum -y install wget
2.接下来我们在 Centos7 系统下使用 yum 命令安装 MySQL
1:先去官网下载Yum资源包(MySQL使用的是8.0版本):https://dev.mysql.com/downloads/repo/yum/
2:使用命令下载 [root@localhost ZL]# wget https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
3:执行命令安装[root@localhost ZL]# rpm -ivh mysql80-community-release-el7-3.noarch.rpm
[root@localhost ZL]# yum install mysql-server
3.注意安装yum install mysql-server会出现错误
错误:Package: mysql-community-client-8.0.16-2.el7.x86_64 (mysql80-community)
Requires: libc.so.6(GLIBC_2.14)(64bit)
错误:Package: mysql-community-server-8.0.16-2.el7.x86_64 (mysql80-community)
Requires: libstdc++.so.6(GLIBCXX_3.4.15)(64bit)
错误:Package: mysql-community-client-8.0.16-2.el7.x86_64 (mysql80-community)
Requires: libstdc++.so.6(GLIBCXX_3.4.15)(64bit)
错误:Package: mysql-community-server-8.0.16-2.el7.x86_64 (mysql80-community)
Requires: libstdc++.so.6(GLIBCXX_3.4.14)(64bit)
错误:Package: mysql-community-client-8.0.16-2.el7.x86_64 (mysql80-community)
Requires: libstdc++.so.6(GLIBCXX_3.4.14)(64bit)
错误:Package: mysql-community-server-8.0.16-2.el7.x86_64 (mysql80-community)
Requires: libstdc++.so.6(GLIBCXX_3.4.17)(64bit)
错误:Package: mysql-community-server-8.0.16-2.el7.x86_64 (mysql80-community)
Requires: libc.so.6(GLIBC_2.17)(64bit)
错误:Package: mysql-community-libs-8.0.16-2.el7.x86_64 (mysql80-community)
Requires: libc.so.6(GLIBC_2.14)(64bit)
错误:Package: mysql-community-server-8.0.16-2.el7.x86_64 (mysql80-community)
Requires: libstdc++.so.6(GLIBCXX_3.4.19)(64bit)
错误:Package: mysql-community-client-8.0.16-2.el7.x86_64 (mysql80-community)
Requires: libstdc++.so.6(GLIBCXX_3.4.18)(64bit)
错误:Package: mysql-community-libs-8.0.16-2.el7.x86_64 (mysql80-community)
Requires: libstdc++.so.6(GLIBCXX_3.4.18)(64bit)
错误:Package: mysql-community-server-8.0.16-2.el7.x86_64 (mysql80-community)
Requires: libstdc++.so.6(GLIBCXX_3.4.18)(64bit)
错误:Package: mysql-community-server-8.0.16-2.el7.x86_64 (mysql80-community)
Requires: systemd
错误:Package: mysql-community-server-8.0.16-2.el7.x86_64 (mysql80-community)
Requires: libstdc++.so.6(CXXABI_1.3.5)(64bit)
错误:Package: mysql-community-libs-8.0.16-2.el7.x86_64 (mysql80-community)
Requires: libstdc++.so.6(CXXABI_1.3.5)(64bit)
错误:Package: mysql-community-server-8.0.16-2.el7.x86_64 (mysql80-community)
Requires: libstdc++.so.6(CXXABI_1.3.7)(64bit)
错误:Package: 2:postfix-2.6.6-8.el6.x86_64 (@base)
Requires: libmysqlclient.so.16()(64bit)
正在删除: mysql-libs-5.1.73-8.el6_8.x86_64 (@base)
libmysqlclient.so.16()(64bit)
Obsoleted By: mysql-community-libs-8.0.16-2.el7.x86_64 (mysql80-community)
Not found
错误:Package: mysql-community-client-8.0.16-2.el7.x86_64 (mysql80-community)
Requires: libstdc++.so.6(CXXABI_1.3.5)(64bit)
错误:Package: mysql-community-server-8.0.16-2.el7.x86_64 (mysql80-community)
Requires: libsasl2.so.3()(64bit)
错误:Package: 2:postfix-2.6.6-8.el6.x86_64 (@base)
Requires: libmysqlclient.so.16(libmysqlclient_16)(64bit)
正在删除: mysql-libs-5.1.73-8.el6_8.x86_64 (@base)
libmysqlclient.so.16(libmysqlclient_16)(64bit)
Obsoleted By: mysql-community-libs-8.0.16-2.el7.x86_64 (mysql80-community)
Not found
错误:Package: mysql-community-client-8.0.16-2.el7.x86_64 (mysql80-community)
Requires: libstdc++.so.6(GLIBCXX_3.4.19)(64bit)
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
解决方法(进到/etc/yum.repos.d目录编辑mysql-community.repo 文件,将enabled设置为0):https://blog.csdn.net/cry1049208942/article/details/84142596
4:启动MySQL、查看MySQL状态
1、 [root@localhost ZL]# systemctl start mysqld
注意:systemctl命令未找到时,可以用service替代(service mysqld start)
最后看到下面信息代表启动成功:
Initializing MySQL database: Installing MySQL system tables...
OK
Filling help tables...
OK
2、查看MySQL状态:[root@localhost ZL]# systemctl status mysqld
注意:systemctl命令未找到时,可以用service替代(service mysqld status)
看到下面信息代表启动成功:
mysqld (pid 3260) is running...
5、查找MySQL链接密码
1、因为本文按照的是8.0的MySQL,所以当你第一次启动MySQL时系统不会初始化任何密码。
2、如果安装的是8.0以下的数据库,当你第一次启动MySQL时,系统会为MySQL根用户生成一个临时密码。 您可以通过运行以下命令找到密码:[root@localhost ZL]# grep 'temporary password' /var/log/mysqld.log,输出信息:2018-06-13T02:19:38.145804Z 1 [Note] A temporary password is generated for root@localhost: RL-#Nf=>g2Wf。localhost后的就是初始密码。
注意:如果这个文件为空:
a.删除原来安装过的mysql残留的数据(这一步非常重要,问题就出在这)
rm -rf /var/lib/mysql
b.重启mysqld服务
systemctl restart mysqld 或者(service musqld restart)
c.再去找临时密码
grep ‘temporary password’ /var/log/mysqld.log
3.然后执行MySQL安装项密码:sudo mysql_secure_installation
会提示你输入密码,如果是8.0的MySQL,直接回车,如果是8.0以下的,输入上边第2步获取的密码。
4.接下来,会提示你输入新的密码和一些其他的设置,一般都选择y即可.
如果设置密码的时候出现下列错误:ERROR 1819 (HY000): Your password does not satisfy the current policy requirements,说明你的密码不符合规范,要重新输入(一般设置成有大小写字符数字和特殊字符的密码就行。并且6-10位最好)。
6、Navicat for mysql进行连接(阿里云配置方式)
1、如果是阿里云ecs服务器的话需要设置开放端口号,在服务器控制台找到 安全组-配置规则-添加安全组规则
20180908175143219.jpeg
2、然后进行Navicat 配置,输入公网IP,端口3306,root,以及密码,然后点击test,发现出现错误:1130-host ... is not allowed to connect to this MySql server
这时候如何解决呢?请看下边:
7、解决130-host ... is not allowed to connect to this MySql server
遇到这个问题首先到mysql所在的服务器上用连接进行处理
1、连接服务器: mysql -u root -p,回车输入密码
1241620-20171005131318255-683574509.png
2、查看当前所有数据库:show databases;(;一定要添加)
1241620-20171005131646286-1982836224.png
3、进入mysql数据库:use mysql;
1241620-20171005131749724-1387433844.png
4、查看mysql数据库中所有的表:show tables;
1241620-20171005131937958-1048454413.png
5、查看user表中的数据:select Host, User,Password from user;
1241620-20171005132311646-432223453.png
6、修改user表中的Host:update user set Host='%' where User='root';
1241620-20171005132640099-1037311838.png
7、最后刷新一下:flush privileges;
1241620-20171005132739865-1075208564.png
8、然后再去Navicat去测试一下,就可以连接成功了。
网友评论