云服务器CentOS安装mysql数据库

之前也不止一次在服务器上安装mysql了,为了以后方便,于是记录下本次安装过程。

开始

准备
  • 服务器:腾讯云服务器
  • 操作系统:CentOS 7.5 64位
  • CPU:1核
  • 内存:2GB
  • 公网带宽:1 Mbps
安装方式
  1. 使用yum方式安装
  2. 自己下载mysql安装包进行安装

腾讯云的CentOS系统自带了yum,所以我这里使用yum方式安装,因为方便啊?

安装步骤

1.查看yum源中是否有mysql
[root@VM_0_2_centos ~]# yum list | grep mysql
2.如果没有mysql-server服务就需要自己安装喽。首先下载mysql的repo源
[root@VM_0_2_centos ~]# wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
3.安装mysql-community-release-el7-5.noarch.rpm包
[root@VM_0_2_centos ~]# sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
4.安装mysql服务
[root@VM_0_2_centos ~]# sudo yum install mysql-server
5.登录mysql

注意:这里可能会报一下的错误

[root@VM_0_2_centos ~]# mysql -uroot
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

原因是/var/lib/mysql文件夹的访问权限问题,修改下访问权限即可:

[root@VM_0_2_centos ~]# sudo chown -R mysql:mysql /var/lib/mysql

然后重启mysql

[root@VM_0_2_centos lib]# service mysqld restart

此时就可以登录mysql了

[root@VM_0_2_centos ~]# mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.6.41 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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.修改mysql密码
mysql > use mysql;
mysql > update user set password=password('这里写你的密码') where user='root';
mysql > exit;
7.允许远程连接mysql

我们会使用navicat等工具远程连接mysql,但是当我们安装了mysql后是不允许远程连接的,因此我们需要对其进行设置。首先先进入服务器上的mysql:

mysql> use mysql;
mysql> grant all privileges  on *.* to root@'%' identified by "你的mysql密码";
mysql> flush privileges;

此时再去使用navicat连接服务器上的mysql,不管你信不信,反正我是连上了,哈哈哈?

更多文章请关注我的个人博客:www.zhyocean.cn

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值