Ubutnu 18.04 下安装MySql 数据库

最近在做Django 相关的农行项目,需要部署测试环境,这里在重头记录一遍,Ubuntu 18下,安装各软件及其Djano相关的部署过程。

先说下,MySql的安装,这里我用的是Ubuntu 18安装方法如下。

apt install mysql-server

等他安装完成,安装完成后,系统默认启动Mysql服务的

安装完成后,使用如下命令登录

mysql -u root -p

 -u 表示选择登录用户,-p表示登录用户的密码,初始化安装是没有密码的,直接回车,就能进入数据库中。

 然后通过

show databases; 

就可以查看当前的所有数据库。

 

 接下来,我们需要对数据库进行初始化操作。

在Ubuntu 命令行输入:

mysql_secure_installation
root@ip-172-31-23-232:/home/ubuntu# mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin? # 要安装验证密码插件吗?

Press y|Y for Yes, any other key for No: N
Please set the password for root here.

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

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. 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  # 删除匿名账户
Success.


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) : N  # 禁止root管理员从远程登录,这里我没有禁止

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : U^HY   # 删除test数据库并取消对它的访问权限

 ... skipping.
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 # 刷新授权表,让初始化后的设定立即生效
Success.

All done! 

再次进入mysql命令行,这里使用刚刚的密码就可以登录进入了。

 之后我们配置mysql 远程登录访问。

编辑配置文件

vim /etc/mysql/mysql.conf.d/mysqld.cnf

找到如下图所示位置,修改

将它注释掉。保存退出。

mysql -u root -p

进入mysql命令行

mysql> grant all on *.* to root@'%' identified by '你的密码' with grant option;

刷新权限

mysql> flush privileges;    # 刷新权限

退出

mysql> exit

执行如下命令,重启mysql

systemctl restart mysql

现在可以直接远程访问myql了。

如果还不可以远程访问,那么请查看服务器的安全组设置,是否打开相应的端口。

到这里,Ubuntu 18 上安装mysql 服务,已经完成。谢谢阅读。感谢点赞,交流。谢谢

猜你喜欢

转载自blog.csdn.net/u012798683/article/details/107312809