MySQL的安装有多种方式,本文章只介绍yum方式的安装,如果是做自动化部署的同学,建议考虑rpm包或tar包的安装方式。
安装前检查
卸载mariadb相关包
[root@kkk ~]
mariadb-libs-5.5.68-1.el7.x86_64
mariadb-5.5.68-1.el7.x86_64
[root@kkk ~]
[root@kkk ~]
安装mysql客户端
[root@kkk ~]
安装mysql服务端
[root@kkk ~]
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* epel: mirrors.bfsu.edu.cn
No package mysql-server available.
Error: Nothing to do
上面这个报错是因为CentOS自带mariadb,需要安装MySQL的话需要使用MySQL社区的repo文件。如果没报错,跳过这一步
[root@kkk ~]
Retrieving http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
Preparing...
Updating / installing...
1:mysql-community-release-el7-5
[root@kkk ~]
-rw-r--r-- 1 root root 1209 Jan 29 2014 /etc/yum.repos.d/mysql-community.repo
-rw-r--r-- 1 root root 1060 Jan 29 2014 /etc/yum.repos.d/mysql-community-source.repo
接下来就可以使用yum安装服务端了。
[root@kkk ~]
登录MySQL
[root@kkk ~]
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
由于本次登录使用的socket的方法,所以需要socket文件,报错是因为没有这个文件。排查发现是安装完成后没有启动服务。(前面少了一步启动,就不往上面补了。)
[root@kkk ~]
● mysqld.service - MySQL Community Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: inactive (dead)
[root@kkk ~]
这下就可以登录了,由于是第一次登录没有设置密码,所以密码验证可以直接回车跳过。 注: 有的版本是有初始化密码的,在/var/log/mysqld.log中找到root@localhost,后面就是一个初始化密码。
[root@kkk ~]
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.51 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, 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 for root@localhost = password('root');
创建新用户,并允许远程登录
create user 'test'@'%' identified by 'test';
设置指定ip段访问
update user set host = '192.168.%.%' where user = 'test';
设置后需重启服务,或
flush privileges;
|