怎样在Ubuntu18.04中安装MySQL

40次阅读
没有评论

共计 1984 个字符,预计需要花费 5 分钟才能阅读完成。

自动写代码机器人,免费开通

这篇文章给大家介绍怎样在 Ubuntu18.04 中安装 MySQL,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

1. 安装 MySQL

在 Ubuntu 中,默认情况下,只有最新版本的 MySQL 包含在 APT 软件包存储库中, 要安装它,只需更新服务器上的包索引并安装默认包 apt-get。

# 命令 1
sudo apt-get update
sudo apt-get install mysql-server

怎样在 Ubuntu18.04 中安装 MySQL

2. 配置 MySQL2.1 初始化配置

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 (我的选项)
Please set the password for root here...
New password: (输入密码)
Re-enter new password: (重复输入)
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them...
Remove anonymous users? (Press y|Y for Yes, any other key for No) : N (我的选项)
Normally, root should only be allowed to connect from
 localhost . This ensures that someone cannot guess at
the root password from the network...
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y (我的选项)
By default, MySQL comes with a database named  test  that
anyone can access...
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N (我的选项)
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y (我的选项)

2.2 检查 mysql 服务状态

systemctl status mysql.service

显示如下结果说明 mysql 服务是正常的:

怎样在 Ubuntu18.04 中安装 MySQL

3. 配置远程访问

在 Ubuntu 下 MySQL 缺省是只允许本地访问的,使用 workbench 连接工具是连不上的;

如果你要其他机器也能够访问的话,需要进行配置;

3.1 首先用根用户进入

sudo mysql -uroot -p

登入 root 进行其他设置:

怎样在 Ubuntu18.04 中安装 MySQL

GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY  123456

怎样在 Ubuntu18.04 中安装 MySQL

其中 root@localhos,localhost 就是本地访问,配置成 % 就是所有主机都可连接;

第二个 123456 为你给新增权限用户设置的密码,% 代表所有主机,也可以是具体的 ip;

不过这随设置了 % 但我 root 通过工具还是登陆不进去,可能是为了安全性,所以新建数据库和用户;

3.2 新建数据库和用户

用 root 用户新建数据和用作远程访问的用户

##1  创建数据库 weixx
CREATE DATABASE weixx;
##2  创建用户 wxx(密码 654321)  并允许 wxx 用户可以从任意机器上登入 mysql 的 weixx 数据库
GRANT ALL PRIVILEGES ON weixx.* TO wxx@ %  IDENTIFIED BY  654321

4. 使用 workbench 连接数据库

打开 workbench 进行连接配置:

怎样在 Ubuntu18.04 中安装 MySQL

配置完成后,在主界面选择 weixx 数据库进行连接:

怎样在 Ubuntu18.04 中安装 MySQL

关于怎样在 Ubuntu18.04 中安装 MySQL 就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

向 AI 问一下细节

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-12-04发表,共计1984字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)