Centos手动安装MySQL数据库、设置MySQL数据库密码、设置MySQL数据库远程
清理环境
mariadb是从MySQL来的,是它的一个分支,需要清理掉
查看是否已安装
rpm -qa |grep -i mysql rpm -qa |grep -i mariadb
rpm -e 加上包名,把mariadb包清掉
如rpm -e mariadb
rpm删除时如果有依赖关系,可以用yum remove +包名 ,来删除mariadb
如yum remove mariadb
安装Mysql
Mysql下载处
MySQL :: Download MySQL Community Server https://dev.mysql.com/downloads/mysql/
一、手动安装
yum install -y net-tools rpm -ivh https://cdn.mysql.com/archives/mysql-5.7/mysql-community-common-5.7.31-1.el7.x86_64.rpm rpm -ivh https://cdn.mysql.com/archives/mysql-5.7/mysql-community-libs-5.7.31-1.el7.x86_64.rpm rpm -ivh https://cdn.mysql.com/archives/mysql-5.7/mysql-community-client-5.7.31-1.el7.x86_64.rpm rpm -ivh https://cdn.mysql.com/archives/mysql-5.7/mysql-community-server-5.7.31-1.el7.x86_64.rpm
二、重置mysql密码
1、配置mysqlvi /etc/my.cnf
在[mysqld]
后面任意一行添加 skip-grant-tables
用来跳过密码验证的过程。
保存文档并退出
2、接下来我们需要重启MySQL:/etc/init.d/mysql restart
3、重启之后输入mysql
即可进入mysql。
进入到终端当中,敲入 mysql -u root -p 命令然后回车,当需要输入密码时,直接按enter键,便可以不用密码登录到数据库当中
mysql> use mysql; mysql> update user set password=password("你的新密码") where user="root"; mysql> flush privileges; mysql> quit
4、将MySQL的登录设置修改回来:vi /etc/my.cnf
,将刚才加的skip-grant-tables
删除并保存退出。
5、重启数据库:service mysqld restart
6、尝试新密码登录
mysql -u root -p 输入新密码
三、MySQL允许远程登录
设置root允许任意ip远程
use mysql; grant all PRIVILEGES on *.* to root@'%' identified by '数据库密码'; flush privileges;
或者
设置root指定ip远程,
如允IP:192.168.192.168
use mysql; grant all PRIVILEGES on *.* to root@'192.168.192.168' identified by '数据库密码'; flush privileges;
其它命令
看是否有mysql进程:ps –ef | grep –i mysql
看是否有mysql服务:ps –ef | grep mysql
启动mysql服务:service mysql start
停止mysql服务:service mysql stop
重启mysql服务:service mysql restart