云服务器Linux环境下中安装mysql

闲话不扯直接来干货,今天咱们就在云服务器linux环境下安装mysql,并设置密码配置远程可以访问(默认只能在安装宿主机进行访问)。

步骤一:配置仓库准备安装mysql
进入系统的/etc/yum.repos.d/文件夹下进行以下操作:
①创建mysql56-community.repo文件
②在文件内键入以下内容
③进行安装

操作代码:

[root@VM_0_12_centos ~]# cd /etc/yum.repos.d/  //进入目标文件夹
[root@VM_0_12_centos ~]# vim mysql56-community.repo //①创建目标文件
//②键入以下内容
[mysql56-community]
    name=MySQL 5.6 Community Server
    baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
    enabled=1
    gpgcheck=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
    
    注意:如果需要安装mysql5.7只需要将baseurl修改为以下即可 
    		baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
[root@VM_0_12_centos ~]# yum install mysql-community-server //③安装

安静的等待程序安装即可(因为此仓库配置的为网络资源下载时间与网速有关),若出现类似以下文字描述则证明mysql安装成功。
在这里插入图片描述
步骤二:启动mysql配置数据库用户密码
若步骤一正常完成那么就可以跟着小编一起完成步骤二的相关配置了,本步骤配置主要是进行MySQL服务的启动以及对数据库密码进行设置,并且能够掌握mysql舒服的启动、信息查看和服务停止 最后掌握linux命令行方式进行mysql数据库的密码设置以及登录基本的操作
①启动服务
②设置密码
③命令行登入
进行到标号3 即可完成数据库的启动,以下命令属于拓展
④远程第三方客户端登入
代码:

[root@VM_0_12_centos yum.repos.d]# systemctl start mysql //①启动服务 出现如下提示则证明mysql服务已经正常启动
[root@VM_0_12_centos yum.repos.d]# systemctl status  mysql //查看该服务的启动状态 若出现绿色active (running)则证明mysql服务启动成功
● mysqld.service - MySQL Community Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2020-02-17 18:38:49 CST; 11s ago
  Process: 477 ExecStartPost=/usr/bin/mysql-systemd-start post (code=exited, status=0/SUCCESS)
  Process: 412 ExecStartPre=/usr/bin/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 476 (mysqld_safe)
   CGroup: /system.slice/mysqld.service
           ├─476 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
           └─642 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --...

Feb 17 18:38:48 VM_0_12_centos mysql-systemd-start[412]: Please report any problems at http://bugs.mysql.com/
Feb 17 18:38:48 VM_0_12_centos mysql-systemd-start[412]: The latest information about MySQL is available on th... at
Feb 17 18:38:48 VM_0_12_centos mysql-systemd-start[412]: http://www.mysql.com
Feb 17 18:38:48 VM_0_12_centos mysql-systemd-start[412]: Support MySQL by buying support/licenses at http://sh...com
Feb 17 18:38:48 VM_0_12_centos mysql-systemd-start[412]: Note: new default config file not created.
Feb 17 18:38:48 VM_0_12_centos mysql-systemd-start[412]: Please make sure your config file is current
Feb 17 18:38:48 VM_0_12_centos mysql-systemd-start[412]: WARNING: Default config file /etc/my.cnf exists on th...tem
Feb 17 18:38:48 VM_0_12_centos mysqld_safe[476]: 200217 18:38:48 mysqld_safe Logging to '/var/log/mysqld.log'.
Feb 17 18:38:48 VM_0_12_centos mysqld_safe[476]: 200217 18:38:48 mysqld_safe Starting mysqld daemon with data...ysql
Feb 17 18:38:49 VM_0_12_centos systemd[1]: Started MySQL Community Server.
Hint: Some lines were ellipsized, use -l to show in full.

[root@VM_0_12_centos yum.repos.d]# mysqladmin -u root -p password  //②设置密码
Enter password:  //敲击回车
New password:  //输入数据库自定义密码敲击回车 (此处输入密码将不会显示保证密码的安全性)
Confirm new password:  //再次重复输入以上密码敲击回车 出现以下信息则证明设置成功

[root@VM_0_12_centos ~]# mysql -u root -p //③命令行登入
Enter password:  //输入以上设置好的密码 提示以下信息则说明我们已经成功的登入mysql中
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.6.47 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, 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>

截止到此处mysql已经成功安装并且能够进行本操作系统内部进行访问,最终我们数据库是为应用所服务,随着用户的使用ip不固定,超出当前系统的范围那么我们还能进行访问吗? 请看下面的界面,该图为在window系统中使用navicat进行数据库访问,很明显我们看到云服务器mysql server已经拒绝了远程访问
在这里插入图片描述
步骤三:进行允许远程连接的相关授权
登入系统中后登入mysql

键入以下命令可查看mysql中的所有数据库

mysql> show databases; //命令
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

键入以下命令可以选择一个数据库进行使用

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> show tables; //命令
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| innodb_index_stats        |
| innodb_table_stats        |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| servers                   |
| slave_master_info         |
| slave_relay_log_info      |
| slave_worker_info         |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
28 rows in set (0.00 sec)

接下来的操作就是正常的sql查询操作了

mysql> select user,host,password from user;//命令(查询mysql数据库的用户名密码以及对应到的允许访问主机)
+------+-------------------+-------------------------------------------+
| user | host              | password                                  |
+------+-------------------+-------------------------------------------+
| root | localhost         | *0745273DC10530sfdfvdsdssbfbfsbgdvsdsdbsd |
| root | vm\_0\_12\_centos |                                           |
| root | 127.0.0.1         |                                           |
| root | ::1               |                                           |
|      | localhost         |                                           |
|      | vm\_0\_12\_centos |                                           |
+------+-------------------+-------------------------------------------+
6 rows in set (0.00 sec)

mysql> grant all privileges on *.* to '【A】'@'%' identified by '【B】' with grant option; //进行此操作后远程连接即可访问数据库 将此处的【A】改为你的数据库默认用户名root 【B】改为mysql登录的密码
Query OK, 0 rows affected (0.00 sec)

mysql> select user,host,password from user;
+------+-------------------+-------------------------------------------+
| user | host              | password                                  |
+------+-------------------+-------------------------------------------+
| root | localhost         | *0745273DC10530sfdfvdsdssbfbfsbgdvsdsdbsd |
| root | vm\_0\_12\_centos |                                           |
| root | 127.0.0.1         |                                           |
| root | ::1               |                                           |
|      | localhost         |                                           |
|      | vm\_0\_12\_centos |                                           |
| root | %                 | *0745273DC10530sfdfvdsdssbfbddssgdvsdsdbsd |
+------+-------------------+-------------------------------------------+
7 rows in set (0.00 sec)

此时已经完成远程客户端访问的授权工作,现在我们再来进行测试。
在这里插入图片描述
若上述远程访问仍无法连接成功请进行以下操作
云服务防火墙改为安全组,进入云服务器的控制台进行相关安全组的配置:
这里以腾讯云服务器为例,其他云类似
在这里插入图片描述
到此为止就完成了,如有疑问可进行联系

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Caofuqiang_521

你的鼓励是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值