阿里云服务器上创建mysql服务器,并且远程连接mysql

阿里云服务器:centos8 安装 mysql 8.0

1.命令:安装命令
# yum install mysql
# yum install mysql-server
# yum install mysql-devel
2.启动命令:
# service mysqld restart 或 # systemctl start mysqld
查看数据库状态:
# systemctl status mysqld

[root@iZ2ze9u81t8mudvi0a9c3cZ etc]# systemctl status mysqld
● mysqld.service - MySQL 8.0 database server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
   Active: **active (running)** since Sat 2020-08-22 12:49:32 CST; 13min ago
  Process: 1815 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
  Process: 1702 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0/SUCCESS)
  Process: 1677 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
 Main PID: 1750 (mysqld)
   Status: "Server is operational"
    Tasks: 40 (limit: 11516)
   Memory: 469.3M
   CGroup: /system.slice/mysqld.service
           └─1750 /usr/libexec/mysqld --basedir=/usr

Aug 22 12:49:28 iZ2ze9u81t8mudvi0a9c3cZ systemd[1]: Starting MySQL 8.0 database server...
Aug 22 12:49:32 iZ2ze9u81t8mudvi0a9c3cZ systemd[1]: Started MySQL 8.0 database server.

3.初次安装mysql,root账户没有密码。
# mysql -u root

复制代码
[root@yl-web yl]# mysql -u root 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.26 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.01 sec)

4.设置密码命令:# alter user ‘root’ @‘localhost’ identified with mysql_native_password by ‘自己的密码’;
退出命令:# exit
5.使用密码登录:# mysql -u root -p

[root@iZ2ze9u81t8mudvi0a9c3cZ etc]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.17 Source distribution

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

6.创建远程登录用户:

create user ‘root’@’%’ identified by ‘你的密码’;

7.授权root 用户:

grant all privileges on . to ‘root’@’%’;

查看user 表信息 root用户的host 为%:

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select user,host from user
    -> ;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| root             | %         |
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)

mysql> 

8.刷新权限

flush privileges;

exit

9.开放3306端口
# systemctl status firewalld 查看防火墙状态
# systemctl start firewalld 开启防火墙
# systemctl stop firewalld 关闭防火墙
# firewall-cmd --zone=public --add-port=3306/tcp --permanent 开放3306端口
# sudo systemctl restart firewalld 重新加载防火墙
10.配置阿里云服务器上的安全组件配置,开放3306端口
在这里插入图片描述
点击去:
在这里插入图片描述

11.利用navicat 连接即可,要保证 mysql 是启动状态,否则 会报10061的错误
注意:mysql配置文件为/etc/my.cnf

12 以上为自己搭建过程,这篇博客写的比较完善推荐参考:https://my.oschina.net/warm6Y/blog/3207345/print

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值