目录

一,下载MYSQL安装和配置

二,外网连接阿里云数据库


一,下载MYSQL安装和配置

1.切换到 /app/soft/

cd /app/soft/

2.创建mysql文件夹

mkdir mysql

3.切换到mysql文件夹下

cd mysql

4,下载mysql8.0安装包,等待下载成功

wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz

5,解压mysql8.0安装包

tar xvJf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz

6,重命名解压出来的文件夹,这里改成mysql-8.0

mv mysql-8.0.20-linux-glibc2.12-x86_64 mysql-8.0

7,mysql-8.0文件夹下创建data文件夹 存储文件

mkdir data

8,分别创建用户组以及用户和密码(如果提示已存在说明之前有创建过了)

groupadd mysql useradd -g mysql mysql

9,授权刚刚新建的用户

chown -R mysql.mysql /app/soft/mysql/mysql-8.0 chmod 750 /app/soft/mysql/mysql-8.0/data -R

10,配置环境,编辑/etc/profile文件

vim /etc/profile#--------------------------#点击键盘上的i键,进入输入模式,在配置文件最后增加一行:#--------------------------export PATH=$PATH:/app/soft/mysql/mysql-8.0/bin:/usr/local/mysql/mysql-8.0/lib#添加完成后,按Esc键退出输入模式,进入命令模式,输入:wq,保存并退出#然后在输入cat /etc/profile查看是否保存成功,效果如下:↓↓↓↓↓↓

11,在配置完环境变量后,使配置文件生效

source /etc/profile

12,编辑my.cnf文件

[mysql]default-character-set=utf8mb4[client]port=3306socket=/var/lib/mysql/mysql.sock[mysqld]port=3306server-id=3306user=mysqlgeneral_log = 1general_log_file= /var/log/mysql/mysql.log#skip-grant-tablessocket=/var/lib/mysql/mysql.sockbasedir=/app/soft/mysql/mysql-8.0datadir=/app/soft/mysql/mysql-8.0/datalog-bin=/app/soft/mysql/mysql-8.0/data/mysql-bininnodb_data_home_dir=/app/soft/mysql/mysql-8.0/datainnodb_log_group_home_dir=/app/soft/mysql/mysql-8.0/data/character-set-server = utf8mb4lower_case_table_names=1autocommit=1default_authentication_plugin=mysql_native_passwordsymbolic-links=0# Disabling symbolic-links is recommended to prevent assorted security risks# Settings user and group are ignored when systemd is used.# If you need to run mysqld under a different user or group,# customize your systemd unit file for mariadb according to the# instructions in http://fedoraproject.org/wiki/Systemd[mysqld_safe]log-error=/app/soft/mysql/mysql-8.0/data/mysql.logpid-file=/app/soft/mysql/mysql-8.0/data/mysql.pidclient]#port=3306socket=/var/lib/mysql/mysql.sock[mysqld]port=3306server-id=3306user=mysqlbind-address = 0.0.0.0general_log = 1general_log_file= /var/log/mysql/mysql.logsocket=/var/lib/mysql/mysql.sockbasedir=/app/soft/mysql/mysql-8.0datadir=/app/soft/mysql/mysql-8.0/datalog-bin=/app/soft/mysql/mysql-8.0/data/mysql-bininnodb_data_home_dir=/app/soft/mysql/mysql-8.0/datainnodb_log_group_home_dir=/app/soft/mysql/mysql-8.0/data/character-set-server=utf8mb4lower_case_table_names=1autocommit=1default_authentication_plugin=mysql_native_passwordsymbolic-links=0

13,切换到/app/soft/mysql/mysql-8.0/bin目录下

cd bin

14,初始化基础信息,得到数据库的初始密码(在/app/soft/mysql/mysql-8.0/bin目录下执行)

./mysqld --user=mysql --basedir=/usr/local/mysql/mysql-8.0 --datadir=/usr/local/mysql//mysql-8.0/data/ --initialize

15,复制 mysql.server 文件,在/app/soft/mysql/mysql-8.0目录下执行

cp -a ./support-files/mysql.server /etc/init.d/mysql cp -a ./support-files/mysql.server /etc/init.d/mysqld

16,赋予权限

chown 777 /etc/my.cnf chmod +x /etc/init.d/mysql chmod +x /etc/init.d/mysqld

17,检查一下/var/lib/mysql是否存在,否则进行创建

mkdir /var/lib/mysqlchown -R mysql:mysql /var/lib/mysql/

18,启动数据库,有SUCCESS字眼说明MySQL安装完成

service mysql start #出现SUCCESS 说明启动成功,效果图如下:

19,修改数据库密码,mysql中远程连接授权

use mysql;create user root@'%' identified by '设置的密码';grant all privileges on *.* to root@'%' with grant option;###刷新权限flush privileges;

二,外网连接阿里云数据库

1,在阿里云服务器中开放3306端口

2,修改配置,bind-address改为0.0.0.0

vi /etc/my.cnf

3,登录mysql修改系统表user

use mysql ;select user,host from user;

use mysql;Grant all privileges on *.* to 'root'@'%' identified by 'password' with grant option;flush privileges;

4,重启mysql服务:service mysql restart

5,连接navicat;(大功告成);

写文章真的不容易,各位老爷点个收藏和赞再走吧。

可能遇到的问题:

因为我的版本是8的,所以执行授权语句会报错

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password'WITH GRANT OPTION

root权限不够,登录mysql后通过SELECT * FROM mysql.user;命令查询权限信息,可以看到root对应的很多权限都是no,如下图所示:


解决方案:

将root权限全部修改为yes,执行如下代码(记得退出mysql,重启服务):

use mysql; update user set Update_priv ='Y' where user = 'root';update user set Select_priv ='Y' where user = 'root';update user set Insert_priv ='Y' where user = 'root';update user set Update_priv ='Y' where user = 'root';update user set Delete_priv ='Y' where user = 'root';update user set Create_priv ='Y' where user = 'root';update user set Drop_priv ='Y' where user = 'root';update user set Reload_priv ='Y' where user = 'root';update user set Shutdown_priv ='Y' where user = 'root';update user set Process_priv ='Y' where user = 'root';update user set File_priv ='Y' where user = 'root';update user set Grant_priv ='Y' where user = 'root';update user set References_priv ='Y' where user = 'root';update user set Index_priv ='Y' where user = 'root';update user set Alter_priv ='Y' where user = 'root';update user set Show_db_priv ='Y' where user = 'root';update user set Super_priv ='Y' where user = 'root';update user set Create_tmp_table_priv ='Y' where user = 'root';update user set Lock_tables_priv ='Y' where user = 'root';update user set Execute_priv ='Y' where user = 'root';update user set Repl_slave_priv ='Y' where user = 'root';update user set Repl_client_priv ='Y' where user = 'root';update user set Create_view_priv ='Y' where user = 'root';update user set Show_view_priv ='Y' where user = 'root';update user set Create_routine_priv ='Y' where user = 'root';update user set Alter_routine_priv ='Y' where user = 'root';update user set Create_user_priv ='Y' where user = 'root';update user set Event_priv ='Y' where user = 'root';update user set Trigger_priv ='Y' where user = 'root';// 退出mysqlexit// 重启mysql服务service mysqld restart