阿里云ubuntu安装mysql_阿里云Ubuntu服务器安装MySQL

安装 MySQL

更新服务器上的包索引

sudo apt-get update

安装默认包

sudo apt-get install mysql-server

配置 MySQL

初始化配置

sudo mysql_secure_installation

配置项较多,如下所示:

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 (我的选项)

检查mysql服务状态

systemctl status mysql.service

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

mysql.service - MySQL Community Server

Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)

Active: active (running) since Sun 2020-02-23 00:21:57 CST; 8min ago

Main PID: 1679 (mysqld)

Tasks: 28 (limit: 2339)

CGroup: /system.slice/mysql.service

└─1679 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid

Feb 23 00:21:57 xxxxxxxx systemd[1]: Starting MySQL Community Server...

Feb 23 00:21:57 xxxxxxxx systemd[1]: Started MySQL Community Server.

配置远程访问

在Ubuntu下MySQL缺省是只允许本地访问的,如果你要其他机器也能够访问的话,需要进行配置:

sudo mysql -uroot -p

输入

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY "123456";

or

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

其中root@localhost,localhost就是本地访问,配置成%就是所有主机都可连接;'123456'为你给新增权限用户设置的密码,%代表所有主机,也可以是具体的ip;

编辑配置文件

sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf

将 bind-address 的值修改为 0.0.0.0

重启MySQL

sudo /etc/init.d/mysql restart

网络安全组配置

点击==配置安全组==后==添加安全组规则==

93ad63140573

image.png

测试

MySQL命令

启动MySQL:service mysql start

停止MySQL:service mysql stop

重启MySQL:sudo /etc/init.d/mysql restart

确认是否启动成功:sudo netstat -tap | grep mysql

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值