mysql安装指定版本设置外网连接

99 阅读2分钟

mysql下载

下载社区版

我的图床仓库(万一没网进不去了呢)

image-20220222210244726

image-20220222200122206

image-20220222200821803

image-20220226102727422

在压缩安装后可更改端口,需注意同一库下,只可同时运行一个数据库。

修改端口后无需再次创建数据库对象,重新启动即可。

image-20220222200917733

在命令行下修改数据库加密插件

linux下安装MySQL

lcl@us:~$ cat /etc/os-release 查看当前系统

image-20220222201609037

查看MySQL当前运行状态,如遇图中所示,退不出去按ctrl+c即可退出。

mysql> select version(); 查看mysql当前版本

contos7安装指定版本

image-20220222201641175

**安装指定mysql版本**
​
http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5.6/
​
MySQL-5.6.36-1.el7.src.rpm
​
MySQL-5.6.36-1.el7.x86_64.rpm-bundle.tar
​
MySQL-5.6.36-1.el7.x86_64.rpm-bundle.tar.asc
​
MySQL-5.6.36-1.el7.x86_64.rpm-bundle.tar.md5
​
注意: el6标识centos 6,el7标识centos 7
​
下载[MySQL-5.6.36-1.el7.x86_64.rpm-bundle.tar](http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5.6/MySQL-5.6.36-1.el7.x86_64.rpm-bundle.tar)
​
\2. 环境检查
​
2.1 centos版本
​
PC server X86系列:
​
  I386—I686都是32位
​
  x86_64是64位
​
查看系统版本:cat /etc/os-release 或 cat /etc/redhat-release
​
查看内核版本:uname -a
​
2.2 卸载MariaDB
​
注意:centos7默认自带mariadb
​
查看当前安装的mariadb包:rpm –qa|grep mariadb
 强制卸载: rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64 
​
2.3 检查MySQL
​
rpm -qa|grep -i mysql
​
查找mysql文件夹
​
  find / -name mysql
​
删除配置文档
​
  rm -rf /etc/my.cnf
​
再次查找机器是否安装mysql
​
  rpm -qa|grep -i mysql
​
\3. 安装MySQL
​
3.1 安装
​
rpm -ivh MySQL-server-5.6.36-1.el7.x86_64.rpm
​
rpm -ivh MySQL-devel-5.6.36-1.el7.x86_64.rpm
​
rpm -ivh MySQL-client-5.6.36-1.el7.x86_64.rpm
​
或者:rpm -ivh MySQL-*.rpm
​
3.2 移动配置文件
​
#默认/etc下无配置文件,可把模板配置文件复制过来cp /usr/share/mysql/my-default.cnf /etc/my.cnf
​
3.3 设置root密码
​
#启动mysql
​
service mysql start 
​
#查看root账号密码cat /root/.mysql_secret 
​
#使用上一步查到的密码如NeHgMTRaW2gc2EXf登陆
​
mysql -uroot –pNeHgMTRaW2gc2EXf
​
#设置密码为123456
​
mysql> SET PASSWORD = PASSWORD('123456'); 
​
mysql> exit
​
3.4 远程登录用户设置
mysql> use mysql;
​
mysql> select host,user,password from user;
​
mysql> update user set password=password('123456') where user='root';
​
mysql> update user set host='%' where user='root' and host='localhost';
​
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
​
#操作完切记刷新权限
​
mysql> flush privileges;
​
mysql> exit

设置MySQL外网连接

ubuntu下

sudo mysql -uroot 进入数据库
​
 
​
mysql> show databases
​
  -> ;
​
+--------------------+| Database      |+--------------------+| information_schema || mysql       || performance_schema || sys        |+--------------------+4 rows in set (0.04 sec)
​
 
​
mysql> select version();
​
+-------------------------+| version()        |+-------------------------+| 8.0.28-0ubuntu0.20.04.3 |+-------------------------+1 row in set (0.00 sec)
​
 
​
mysql> select host,user,plugin from mysql.user;
​
+-----------+------------------+-----------------------+| host   | user       | plugin        |+-----------+------------------+-----------------------+| %     | lcl       | caching_sha2_password || localhost | debian-sys-maint | caching_sha2_password || localhost | mysql.infoschema | caching_sha2_password || localhost | mysql.session   | caching_sha2_password || localhost | mysql.sys    | caching_sha2_password || localhost | root       | auth_socket      |+-----------+------------------+-----------------------+6 rows in set (0.00 sec)
​
 
​
mysql> create user lzb identified by'819819';
​
Query OK, 0 rows affected (0.02 sec)
​
 
​
mysql> select host,user,plugin,account_locked from mysql.user
​
  -> ;
​
+-----------+------------------+-----------------------+----------------+| host   | user       | plugin        | account_locked |+-----------+------------------+-----------------------+----------------+| %     | lcl       | caching_sha2_password | N       || %     | lzb       | caching_sha2_password | N       || localhost | debian-sys-maint | caching_sha2_password | N       || localhost | mysql.infoschema | caching_sha2_password | Y       || localhost | mysql.session  | caching_sha2_password | Y       || localhost | mysql.sys    | caching_sha2_password | Y       || localhost | root       | auth_socket      | N       |+-----------+------------------+-----------------------+----------------+7 rows in set (0.00 sec)

修改加密插件

image-20220222201943711

退出数据库修改mysqld.cnf文件中的限制网址,注释掉127开头的ip即可**
​
lcl@us:/etc/mysql/mysql.conf.d$ cat mysqld.cnf
​
## The MySQL database server configuration file.## One can use all long options that the program supports.# Run program with --help to get a list of available options and with# --print-defaults to see which it would actually understand and use.## For explanations see# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
​
 
​
# Here is entries for some specific programs# The following values assume you have at least 32M ram
​
 
​
[mysqld]
​
## * Basic Settings#
​
user      = mysql
​
# pid-file  = /var/run/mysqld/mysqld.pid# socket   = /var/run/mysqld/mysqld.sock# port  = 3306# datadir  = /var/lib/mysql
​
 
​
 
​
# If MySQL is running as a replication slave, this should be# changed. Ref https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_tmpdir# tmpdir   = /tmp## Instead of skip-networking the default is now to listen only on# localhost which is more compatible and is not less secure.#bind-address      = 127.0.0.1#mysqlx-bind-address  = 127.0.0.1## * Fine Tuning#
​
key_buffer_size     = 16M
​
# max_allowed_packet  = 64M# thread_stack     = 256K
​
 
​
# thread_cache_size    = -1
​
 
​
# This replaces the startup script and checks MyISAM tables if needed# the first time they are touched
​
myisam-recover-options = BACKUP
​
 
​
# max_connections    = 151
​
 
​
# table_open_cache    = 4000
​
 
​
## * Logging and Replication## Both location gets rotated by the cronjob.## Log all queries# Be aware that this log type is a performance killer.# general_log_file    = /var/log/mysql/query.log# general_log       = 1## Error log - should be very few entries.#
​
log_error = /var/log/mysql/error.log
​
## Here you can see queries with especially long duration# slow_query_log        = 1# slow_query_log_file  = /var/log/mysql/mysql-slow.log# long_query_time = 2# log-queries-not-using-indexes## The following can be used as easy to replay backup logs or for replication.# note: if you are setting up a replication slave, see README.Debian about#    other settings you may need to change.# server-id       = 1# log_bin            = /var/log/mysql/mysql-bin.log# binlog_expire_logs_seconds  = 2592000
​
max_binlog_size  = 100M
​
# binlog_do_db     = include_database_name# binlog_ignore_db   = include_database_name
​
lcl@us:/etc/mysql/mysql.conf.d$ sudo vim mysqld.cnf
​
 
​
sudo systemctl restart mysql 重启数据库
​
sudo systemctl status mysql 查看数据库状态
​
**在MySQL中设置外网账号**
​
mysql> create user a1 identified by ‘a1’;
​
mysql> grant all on *.* to a1;

contos下

mysql内的设置和Ubuntu一样
​
系统设置把etc 目录下的my.cnf 修改添加
​
port=3306bind-address=0.0.0.0
​
即可
​
然后开放防火墙3306端口,重新启动防火墙
​
[root@localhost ~]# firewall-cmd --state
​
running
​
[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
​
success
​
[root@localhost ~]# firewall-cmd --reload
​
success

\