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、数据库初始化:
#参考:mysql的安全向导mysql_secure_installation详解 - luokeli - 博客园 (cnblogs.com)
-------------
sudo 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
==========================================================
8、执行授权命令:
sudo mysql -u root -p
--------------------------
8-1
#建议用:ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';
#尝试用:grant all on *.* to root@'%' identified by '你的密码' with grant option;
#用grant ...这一句有时会提示Access denied for user 'root'@'localhost'
#原因是不同版本的mysql有一些差别;
------------------------------------
8-2 flush privileges; # 刷新权限
-------------------------------------------
9、再次查看mysql的状态:
sudo systemctl status mysql
电脑技术 2024-06-01 15:19:17 通过 网页 浏览(247)
共有0条评论!