Ubuntu18.04下安装MySQL(图文教程)
提示以下操作均在root权限下进行。
# 查看有没有安装MySQL
dpkg -l | grep mysql
# 安装MySQL
apt install mysql-server
安装完成之后可以使用如下命令来检查是否安装成功
stat -tap | grep mysql
通过上述命令检查之后,如果看到有 mysql 的socket处于 LISTEN 状态则表示安装成功。
登录mysql数据库可以通过如下命令
mysql -u root -p
-u 表示选择登陆的用户名, -p 表示登陆的用户密码,现在是mysql数据库是没有密码的,Enter passord:处直接回车,就能够进入mysql数据库。
然后通过 sho databases; 就可以查看当前的所有数据库。
接下来,为了确保数据库的安全性和正常运转,对数据库进行初始化操作。这个初始化操作涉及下面5个步骤。
(1)安装验证密码插件。
(2)设置root管理员在数据库中的专有密码。
(3)随后删除匿名账户,并使用root管理员从远程登录数据库,以确保数据库上运行的业务的安全性。
(4)删除默认的测试数据库,取消测试数据库的一系列访问权限。
(5)刷新授权列表,让初始化的设定立即生效。
对于上述数据库初始化的操作步骤,在下面的输出信息旁边我做了简单注释。
root@ubuntu-virtual-machine:~# mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank passord.
VALIDATE PASSWORD PLUGIN can be used to test passords
and improve security. It checks the strength of passord
and allos the users to set only those passords hich are
secure enough. Would you like to setup VALIDATE PASSWORD plugin? #要安装验证密码插件吗?
Press y|Y for Yes, any other key for No: N # 这里我选择N
Please set the passord for root here.
Ne passord: #输入要为root管理员设置的数据库密码
Re-enter ne passord: #输入密码
By default, a MySQL installation has an anonymous user,
alloing anyone to log into MySQL ithout having to have
a user aount created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y #删除匿名账户
Suess.
Normally, root should only be alloed to connect from
'localhost'. This ensures that someone cannot guess at
the root passord from the ork.
Disallo root login remotely? (Press y|Y for Yes, any other key for No) : N #禁止root管理员从远程登录,这里我没有禁止
... skipping.
By default, MySQL es ith a database named 'test' that
anyone can aess. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and aess to it? (Press y|Y for Yes, any other key for No) : y #删除test数据库并取消对它的访问权限
- Dropping test database...
Suess.
- Removing privileges on test database...
Suess.
Reloading the privilege tables ill ensure that all changes
made so far ill take effect immediately.
Reload privilege tables no? (Press y|Y for Yes, any other key for No) : y #刷新授权表,让初始化后的设定立即生效
Suess.
All done!
检查mysql服务状态
systemctl status mysql
显示如下结果说明mysql服务运行是正常的
用mysql -u root -p命令,Enter passord:处输入刚设置的密码,回车,就能够进入mysql数据库。
使用 use mysql; 命令打开mysql命名的数据库,显示当前数据库的表sho tables; 查询user表里的数据select from user;(user表里是mysql数据库的所有账户信息)
现在配置mysql允许远程访问,编辑 /etc/mysql/mysql.conf.d/mysqld.f 配置文件
vim /etc/mysql/mysql.conf.d/mysqld.f
注释掉bind-address = 127.0.0.1
保存退出,然后进入mysql数据库,执行授权命令
mysql -u root -p mysql> grant all on . to root@'%' identified by '你的密码' ith grant option; mysql> flush privileges; # 刷新权限 mysql> exit
然后执行exit命令退出mysql服务,再执行如下命令重启mysql
systemctl restartmysql
现在Windos下可以使用Navicat图形化工具远程连接Ubuntu下的MySQL数据库,输入刚授权远程权限的密码。
这里顺便再分享下Navicat for MySQL 10.1.7安装包
链接: https://pan.baidu./s/12P1BcvQsRetBY0jGIvIL&shfl=shareset 提取码: 8bft
OK,到这里Ubuntu18.04下安装MySQL已经完成了。
操作过程中我遇到了以下错误
E: 无法获得锁 /var/lib/dpkg/lock-frontend - open (11: 资源暂时不可用)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
解决方法,参考自文章https://.jb51./article/172460.htm
以上所述是我给大家介绍的Ubuntu18.04下安装MySQL的方法,电脑维修网希望对大家有所帮助,如果大家有任何疑问请给我留言,我会及时回复大家的。在此也非常感谢大家对考高分网网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
空调维修
- 我的世界电脑版运行身份怎么弄出来(我的世界
- 空调抽湿是什么意思,设置抽湿的温度有什么意
- 方太燃气灶有一个打不着火 怎么修复与排查方法
- 夏季免费清洗汽车空调的宣传口号
- 清洗完空调后出现漏水现象
- iphone6能玩什么游戏(iphone6游戏)
- 如何设置电脑密码锁屏(如何设置电脑密码锁屏
- win10删除开机密码提示不符合密码策略要求
- 电脑w7显示不是正版(w7不是正版怎么解决)
- 万家乐z8热水器显示e7解决 怎么修复与排查方法
- 1匹空调多少瓦数(1匹空调多少瓦)
- 安卓手机连接电脑用什么软件好(关于安卓手机
- 电脑网页看视频卡是什么原因(爱拍看视频卡)
- 华帝燃气灶点火器一直响然后熄火怎么办:问题
- 电脑壁纸怎么换(关于电脑壁纸怎么换的介绍)
- 冬天空调的出风口应该朝什么方向(冬天空调风