腾讯云配置MySQL数据库
腾讯云服务器下载配置MySQL,并配置远程连接访问
·
1.下载MySQL
1.1 查看是否安装MySQL相关配置:
dpkg -l grep mysql
1.2 安装MySQL
sudo apt install mysql-server
1.3 查看是否安装成功:
sudo netstat -tap | grep mysql
如果看到有 mysql 的 socket 处于 LISTEN 状态则表示安装成功
1.4 查看MySQL服务是否已经启动:
service mysql status
执行命令后出现 active(running) 则表示已启动
2. 配置MySQL数据库
2.1 终端输入命令:
sudo 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:
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) : N # #要安装验证密码插件吗? 我选择否
... skipping.
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 # 这里我选择N
... 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) : y
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
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!
2.2 配置MySQL允许远程访问
注释掉 bind-address = 127.0.0.1,保存并退出
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
2.3 登录MySQL
sudo mysql -uroot -p
2.4 用root用户新建数据库和用作远程访问的用户
##1 创建一个数据库 db # 随便起一个名字
CREATE DATABASE db;
##2 创建用户user(user这个名字就是你远程连接数据库时填的用户名) 并允许user用户可以从任意机器上登入mysql的db数据库
GRANT ALL PRIVILEGES ON db.* TO user@"%" IDENTIFIED BY "你的登录密码";
flush privileges;
然后退出mysql
2.5 再执行如下命令重启mysql:
sudo /etc/init.d/mysql restart
2.6 我们需要在腾讯云的防火墙新建规则,开发3306端口
然后就可以连接了
更多推荐
已为社区贡献1条内容
所有评论(0)