Ubuntu18安装与配置mysql

1、安装mysql

sudo apt update

sudo apt install mysql-server

2、安装配置

sudo mysql_secure_installation

#1

VALIDATE PASSWORD PLUGIN can be used to test passwords...

Press y|Y for Yes, any other key for No: N (我的选项)

#2

Please set the password for root here...

New password: (输入密码)

Re-enter new password: (重复输入)

#3

By default, a MySQL installation has an anonymous user,allowing anyone to log into MySQL without having to havea user account created for them...

Remove anonymous users? (Press y|Y for Yes, any other key for No) : N (我的选项)

#4

Normally, root should only be allowed to connect from'localhost'. This ensures that someone cannot guess atthe root password from the network...

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y (我的选项)

#5

By default, MySQL comes with a database named 'test' thatanyone can access...

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N (我的选项)

#6

Reloading the privilege tables will ensure that all changesmade so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y (我的选项) 

Ubuntu18安装与配置mysql_第1张图片
Ubuntu18安装与配置mysql_第2张图片

3、检查mysql服务状态

systemctl status mysql.service

如果出现下图,说明是正常的:

Ubuntu18安装与配置mysql_第3张图片

如果不行,启动mysql服务试试:

sudo service mysql start

4、设置连接mysql不使用sudo

首先,登录:

sudo mysql -uroot

接下来的都是在mysql里敲得。

查看当前用户:

select user,host from mysql.user;

Ubuntu18安装与配置mysql_第4张图片

删除root账号:

drop user root@localhost;

重新创建root:

create user root@localhost identified by 'mysql';

授权:

grant all privileges on *.* to root@localhost with grant option;

刷新权限:

flush privileges;

退出mysql,重新连接:

mysql -uroot -pmysql;

不用加sudo了,搞定。

5、重置密码的方法

SET PASSWORD FOR root@'localhost' = PASSWORD('newpassword');

6、在Ubuntu18.04系统下彻底删除MySQL的方法

转载:Ubuntu18安装并配置mysql

你可能感兴趣的:(Ubuntu18安装与配置mysql)