centos7 安装LNMP(php7)之mysql安装,更改密码,远程受权

1.执行命令 yum install mysql mysql-server mysql-devel -ymysql

知道出现complete!则安装mysql完成sql

当执行数据库

service mysqld restart的时候,出现报错缓存

Redirecting to /bin/systemctl restart mysqld.service
Failed to restart mysqld.service: Unit not found.ide

出现这个缘由,目前待解决,可是在网上找到了另一种彻底兼容mysql的MariaDB数据库工具

执行一下命令spa

# yum install mariadb-server -y 3d

# systemctl start mariadb.servicerest

# systemctl enable mariadb.servicecode

# mysql

 

 

而后修改mysql密码:

MariaDB [(none)]> SHOW DATABASES;  #查看数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> use mysql;  #选择mysql数据库

Database changed
MariaDB [mysql]> update user set password=passworD("yourpassword") where user='root';   #修改数据库密码
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0

MariaDB [mysql]> flush privileges;

MariaDB [mysql]> exit;
完成修改密码,

有时候咱们须要使用naviate这样的工具来链接数据库,可是输入ip用户名和密码以后出现

这是由于没有受权的缘由

1.修改mysql库的user表,将host项,从localhost改成%。%这里表示的是容许任意host访问,若是只容许某一个ip访问,则可改成相应的ip,好比能够将localhost改成192.168.1.123,这表示只容许局域网的192.168.1.123这个ip远程访问mysql。

update user set host = '%' where user = 'root'; 

会有ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'的报错提示,能够忽略。

若是须要受权,单个用户能够执行命令

1.grant all privileges on *.* to 'outUser'@'%' identified by 'password' with grant option

2.flush privileges;   //刷新权限缓存 

再次用navicate就能够连接了

相关文章
相关标签/搜索