ubuntu 18.04下mysql的安装

1、安装mysql

sudo apt install mysql-server

----------------------------------

2、查看mysql的状态

sudo systemctl status mysql

--------------------------------

3、登录mysql数据库

sudo mysql -u root -p

-u 表示选择登陆的用户名, 

-p 表示登陆的用户密码

现在的mysql数据库是没有密码的,Enter password:处直接回车,就能够进入mysql数据库。

--------------------------------

4、查看当前的所有数据库:

show databases; 

(exit)

---------------------------------

5、数据库初始化:

sudo mysql_secure_installation

---------------------------------

mysql的安全向导mysql_secure_installation详解 - luokeli - 博客园 (cnblogs.com)

安装完mysql-server 会提示可以运行mysql_secure_installation
运行mysql_secure_installation会执行几个设置:
  a)为root用户设置密码
  b)删除匿名账号
  c)取消root用户远程登录
  d)删除test库和对test库的访问权限
  e)刷新授权表使修改生效

通过这几项的设置能够提高mysql库的安全。建议生产环境中mysql安装这完成后一定要运行一次mysql_secure_installation

========================================================

 # 要安装验证密码插件吗?

...Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: n

--------------------------------

# 输入要为root管理员设置的数据库密码

Please set the password for root here.

New password:   

Re-enter new password:   

------------------------------------

# 删除匿名账户

Remove anonymous users? (Press y|Y for Yes, any other key for No) :  y   

------------------------------------

# 禁止root管理员从远程登录,这里我没有禁止

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n   

--------------------------------------

# 删除test数据库并取消对它的访问权限

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

----------------------------------------

# 刷新授权表,让初始化后的设定立即生效

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

==========================================================

6、再次查看mysql的状态:

sudo systemctl status mysql

------------------------------------

7、再次登录mysql数据库:

sudo mysql -u root -p

------------------------------------

7-1、打开mysql命名的数据库:

mysql>use mysql; 

------------------------------------

7-2、显示当前数据库的表:

mysql>show tables; 

------------------------------------

7-3、查询user表里的数据:

mysql>select * from user;

(exit)

--------------------------------------

8、执行授权命令:

sudo mysql -u root -p

------------------------------------

8-1 grant all on *.* to root@'%' identified by '你的密码' with grant option;

------------------------------------

8-2 flush privileges;    # 刷新权限

------------------------------------

8-3 exit

-------------------------------------------

9、再次查看mysql的状态:sudo systemctl status mysql

电脑技术 2024-05-15 15:45:28 通过 网页 浏览(120)

共有0条评论!

发表评论

更换一道题!