下载MySql

官网下载链接https://dev.mysql.com/downloads/mysql/5.6.html
按照自己的系统选择下载的版本

uname -a

查看系统位数
图片说明

选择对应的版本下载
图片说明

点击“No thanks, just start my download.”
图片说明

下载完成后使用Xftp上传至Linux

解压

[root@ecs-sn3-medium-2-linux-20191109090235 ~]#tar ‐zxvf mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz

解压压缩包,并将解压后的文件夹重命名为mysql

[root@ecs-sn3-medium-2-linux-20191109090235 ~]# ls
mysql-5.6.46-linux-glibc2.12-x86_64  mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz
[root@ecs-sn3-medium-2-linux-20191109090235 ~]# mv mysql-5.6.46-linux-glibc2.12-x86_64 mysql
[root@ecs-sn3-medium-2-linux-20191109090235 ~]# ls
mysql  mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz
[root@ecs-sn3-medium-2-linux-20191109090235 ~]# 

将mysql移动至/usr/local下

[root@ecs-sn3-medium-2-linux-20191109090235 ~]# mv mysql /usr/local
[root@ecs-sn3-medium-2-linux-20191109090235 ~]# cd /usr/local
[root@ecs-sn3-medium-2-linux-20191109090235 local]# ls
bin  etc  games  include  java  lib  lib64  libexec  mysql  sbin  share  src  tomcat
[root@ecs-sn3-medium-2-linux-20191109090235 local]# 

创建mysql用户及设置权限

创建mysql用户及用户组

[root@ecs-sn3-medium-2-linux-20191109090235 local]# groupadd mysql
[root@ecs-sn3-medium-2-linux-20191109090235 local]# useradd -g mysql mysql
[root@ecs-sn3-medium-2-linux-20191109090235 local]# 

设置mysql文件夹权限

[root@ecs-sn3-medium-2-linux-20191109090235 local]# cd /usr/local
[root@ecs-sn3-medium-2-linux-20191109090235 local]# ls
bin  etc  games  include  java  lib  lib64  libexec  mysql  sbin  share  src  tomcat
[root@ecs-sn3-medium-2-linux-20191109090235 local]# chown -R mysql:mysql mysql
[root@ecs-sn3-medium-2-linux-20191109090235 local]# ll
total 52
drwxr-xr-x.  2 root  root  4096 Sep 23  2011 bin
drwxr-xr-x.  2 root  root  4096 Sep 23  2011 etc
drwxr-xr-x.  2 root  root  4096 Sep 23  2011 games
drwxr-xr-x.  2 root  root  4096 Sep 23  2011 include
drwxr-xr-x   7 root  root  4096 Nov 10 10:24 java
drwxr-xr-x.  2 root  root  4096 Sep 23  2011 lib
drwxr-xr-x.  2 root  root  4096 Sep 23  2011 lib64
drwxr-xr-x.  2 root  root  4096 Sep 23  2011 libexec
drwxr-xr-x  13 mysql mysql 4096 Nov 16 09:54 mysql
drwxr-xr-x.  2 root  root  4096 Sep 23  2011 sbin
drwxr-xr-x.  5 root  root  4096 Jan 30  2019 share
drwxr-xr-x.  2 root  root  4096 Sep 23  2011 src
drwxr-xr-x   9 root  root  4096 Nov 11 15:04 tomcat
[root@ecs-sn3-medium-2-linux-20191109090235 local]# 

安装及配置

[root@ecs-sn3-medium-2-linux-20191109090235 local]# cd mysql/scripts
[root@ecs-sn3-medium-2-linux-20191109090235 scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

启动MySql服务

[root@ecs-sn3-medium-2-linux-20191109090235 ~]# /usr/local/mysql/support-files/mysql.server start
Starting MySQL.                                            [  OK  ]
[root@ecs-sn3-medium-2-linux-20191109090235 ~]# 

修改密码

[root@ecs-sn3-medium-2-linux-20191109090235 bin]# ./mysqladmin -u root password 'root'
Warning: Using a password on the command line interface can be insecure.
[root@ecs-sn3-medium-2-linux-20191109090235 bin]#

登录MySql

[root@ecs-sn3-medium-2-linux-20191109090235 bin]# ./mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.6.46 MySQL Community Server (GPL)

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>

输入命令

此时用Windows的数据库管理软件还无法进行连接,先输入以下命令

mysql> grant all privileges on *.* to root@'%' identified by 'root';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> 

然后在华为云服务器控制台-安全组开启3306端口,连接成功
图片说明