Linux上安装mysql

查看CentOS自带mysql是否已安装。

1
输入:yum list installed | grep mysql

卸载已经安装的mysql

1
yum -y remove mysql-libs.x86_64

查看yum库上的mysql版本信息(CentOS系统需要正常连接网络)。

1
输入:yum list | grep mysql 或 yum -y list mysql*

安装

1
2
yum install mariadb-server mariadb
启动:systemctl start mariadb

修改root密码

1
2
在一个窗口执行 sudo mysqld_safe --skip-grant-tables --skip-networking &
在另一个窗口通过 mysql -u root 登录mysql

通过如下方式修改密码

1
2
3
4
5
6
update mysql.user set PASSWORD=PASSWORD('123456') where user='root' and host='localhost';
update mysql.user set authentication_string=PASSWORD('123456') where user='root' and host='localhost';
flush privileges;
exit;

ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

查看mysql的版本

1
select version();

1
create database test character set utf8;

创建用户

1
2
3
4
create user test@localhost identified by '123456';
grant all privileges on *.* to test@localhost identified by '123456';
grant all privileges on *.* to test@'%' identified by '123456';
flush privileges;

检查

1
2
[root@snails ~]# netstat -ano |grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN off (0.00/0/0)

Share