Centos7下安装mysql数据库

最近使用centos7安装mysql数据库发现连接不上,以为没有启动服务,然后启动服务时出现这个问题:

Failed to start mysqld.service: Unit not found

搜了一下发现是因为centos7竟然放弃了原来mysql,改用分支版本mariadb,下面是按照步骤。

1、安装数据库

yum install -y mariadb-server

2、启动服务

systemctl start mariadb.service

3、设置开机启动服务

systemctl enable mariadb.service

4、设置管理员密码权限

mysql_secure_installation

下面是具体配置

 Set root password? [Y/n] y
 New password:  <此处输入密码>
 Re-enter new password:  <此处输入密码>
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] n
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y

5、登录数据库,设置远程访问权限

# mysql -u root -p
Enter password: <输入密码>

MariaDB [(none)]> use mysql;
MariaDB [mysql]> select  User,authentication_string,Host from user;
+------+-----------------------+-------------------------+
| User | authentication_string | Host                    |
+------+-----------------------+-------------------------+
| root |                       | localhost               |
| root |                       | iz2zeftx94e1dn2bufv9q5z |
| root |                       | 127.0.0.1               |
| root |                       | ::1                     |
+------+-----------------------+-------------------------+

注意: 这里设置远程连接密码为123456,这里应该为自己的密码(最好复杂一点)

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456';

更新设置

flush privileges;

6、使用Navicat Premium连接数据库就可以了。
附上链接:https://gitee.com/wangguodong/NavicatPremium12.git

参考:
https://blog.csdn.net/miaodichiyou/article/details/99289160
http://www.mamicode.com/info-detail-2025017.html

你可能感兴趣的:(java)