hhzblogs

安装mysql服务器

1、 sudo apt-get install mysql-server 

2、 sudo apt-get install mysql-client 

登录问题

安装成功后,我们会发现我们没有登录的权限。

hhz@hhz-virtual-machine:~$ mysql -u root -p
Enter password: 
ERROR 1698 (28000): Access denied for user \'root\'@\'localhost\'

 

然后发现当我们输入 sudo mysql -u root -p 这个命令的时候可以登录(提示输入密码时直接回车即可),显然这不是我们想要的。

那怎么解决这个问题呢?

解决方案:删除root用户,然后重新创建

1、我们先登录:

hhz@hhz-virtual-machine:~$ sudo mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.23-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2018, 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.

 

2、然后查看用户:

mysql> select user,host from mysql.user;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| debian-sys-maint | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)

 

3、删除root帐号

mysql> drop user \'root\'@\'localhost\';
Query OK, 0 rows affected (0.00 sec)

 

4、重新创建一个root帐号

mysql> create user \'root\'@\'%\' identified by \'123456\';
Query OK, 0 rows affected (0.01 sec)

 

5、接下来我们用 quit; 命令来退出mysql,然后试试用新的帐号登录

hhz@hhz-virtual-machine:~$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.23-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2018, 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.

 

ok,登录问题已经完美解决

远程访问问题

1、授权

mysql> grant all privileges on *.* to \'root\'@\'%\' with grant option;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

 

2、用 sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf 打开这个文件,然后将 bind-address = 127.0.0.1 改成 bind-address = 0.0.0.0 允许任何IP地址访问,如果设置多个请用逗号隔开

3、重启服务: service mysql restart 

4、接下来我们在windows下用Navicat来连接试试

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-07-02
  • 2021-07-21
  • 2021-11-21
  • 2021-10-15
  • 2021-06-05
  • 2021-09-17
  • 2020-04-16
猜你喜欢
  • 2021-05-22
  • 2021-07-14
  • 2022-12-23
  • 2021-05-01
  • 2022-12-23
  • 2021-11-20
相关资源
相似解决方案