1、安装mysql
sudo apt-get install mysql-server
sudo apt-get install mysql-client
sudo apt-get install libmysqlclient-dev
1
2
3
通过sudo netstat -tap | grep mysql检查之后,如果看到有mysql 的socket处于 listen 状态则表示安装成功
登录权限问题
Ubuntu18.04 安装mysql之后,发现普通用户和远程都没有权限连接。
ERROR 1045: Access denied for user: 'root@localhost' (Using
password: YES)
1
2
修改了密码也不对。然后sudo mysql -u root即可登录。这显然不是我们想要的。
2、删除用户创建新用户
删除root,重新创建用户。
首先,登录
sudo mysql -u root
1
然后查看当前用户
SELECT User,Host FROM mysql.user;
+------------------+-----------+
| User | Host |
+------------------+-----------+
| admin | localhost |
| debian-sys-maint | localhost |
| magento_user | localhost |
| mysql.sys | localhost |
| root | localhost |
1
2
3
4
5
6
7
8
9
删除root账号
mysql> DROP USER 'root'@'localhost';
Query OK, 0 rows affected (0,00 sec)
1
2
重新创建root:
mysql> CREATE USER 'root'@'%' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0,00 sec)
1
2
授权
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)
1
2
3
4
5
3、关于重置密码
host为%时允许远程登录
SET PASSWORD FOR root@'localhost' = PASSWORD('password');
1
or
UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';
1
or
USE mysql
UPDATE user SET Password = PASSWORD('newpwd')
WHERE Host = 'localhost' AND User = 'root';
1
2
3
允许任何地方登录
USE mysql
UPDATE user SET Password = PASSWORD('newpwd')
WHERE Host = '%' AND User = 'root';
1
2
3
————————————————
版权声明:本文为CSDN博主「爱学习的狮王」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/study_in/article/details/86721468