之前也不止一次在服务器上安装mysql了,为了以后方便,于是记录下本次安装过程。
开始
准备
- 服务器:腾讯云服务器
- 操作系统:CentOS 7.5 64位
- CPU:1核
- 内存:2GB
- 公网带宽:1 Mbps
安装方式
- 使用yum方式安装
- 自己下载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