1、下载mysql5.7的软件

https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz

2、解压mysql-5.7.20到/usr/local/

[root@mysqlmaster01 ~]# tar xf /software/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz -C /usr/local/

3、正常关闭mysql数据库

[root@mysqlmaster01 ~]# /etc/init.d/mysqld stop

4、拷贝数据目录下的mysql数据库、然后备份重要的数据库文件

[root@mysqlmaster01 mysql_data]# cp -r mysql mysql.old

5、然后进入到/usr/local/目录,把原来的mysql5.6的链接unlink掉

[root@mysqlmaster01 mysql_data]# cd /usr/local/
[root@mysqlmaster01 local]# unlink mysql

[root@mysqlmaster01 local]#ln -sv mysql-5.7.20-linux-glibc2.12-x86_64/ mysql

然后启动mysqld服务

[root@mysqlmaster01 local]#/etc/init.d/mysqld start

6、运行mysql_upgrade

[root@mysqlmaster01 mysql]# bin/mysql_upgrade -s -p输入root密码

-s, --upgrade-system-tables  (仅仅更新系统表)
Only upgrade the system tables, do not try to upgrade the

-f, --force Force execution of SQL statements even if mysql_upgrade
has already been executed for the current version of

mysql版本降级

官网:https://dev.mysql.com/doc/refman/5.7/en/downgrading.html#downgrade-methods

第一种方式: 逻辑降级

1)Dump all databases. For example:

[root@mysqlmaster01 ~]# mysqldump -u root -p --add-drop-table --routines --events --all-databases --force > /root/downgrade.sql
Enter password:
[root@mysqlmaster01 ~]# ll /root/downgrade.sql
-rw-r--r--. 1 root root 661169 Nov 22 09:50 /root/downgrade.sql

2)Shut down the newer MySQL server.

[root@mysqlmaster01 ~]# service mysqld stop
Shutting down MySQL.... SUCCESS!

3)初始化一个旧的MySQL实例,并使用一个新的数据目录。例如,要初始化一个MySQL 5.6实例,使用mysql_install_db:

下载mysql版本的二进制文件,然后重新链接mysql到旧的mysql版本上

[root@mysqlmaster01 ~]#/data/mysql5.5_data

[root@mysqlmaster01 ~]# cd /usr/local/mysql

[root@mysqlmaster01 mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mysql5.5_data

如果初始化5.7的版本,则use mysqld with the --initialize

[root@mysqlmaster01 ~]# mkdir /data/mysql5.6_data
[root@mysqlmaster01 ~]# chown -R mysql.mysql /data/mysql5.6_data/
[root@mysqlmaster01 ~]# cd /usr/local/
[root@mysqlmaster01 local]# ll
total 48
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. 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
lrwxrwxrwx. 1 root root 36 Nov 21 16:15 mysql -> mysql-5.7.20-linux-glibc2.12-x86_64/
drwxr-xr-x. 13 root mysql 4096 Nov 21 15:37 mysql-5.6.38-linux-glibc2.12-x86_64
drwxr-xr-x. 9 root root 4096 Nov 21 16:14 mysql-5.7.20-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root 4096 Sep 23 2011 sbin
drwxr-xr-x. 5 root root 4096 Aug 4 09:54 share
drwxr-xr-x. 2 root root 4096 Sep 23 2011 src
[root@mysqlmaster01 local]# unlink mysql
[root@mysqlmaster01 local]# ln -sv mysql-5.6.38-linux-glibc2.12-x86_64/ mysql
`mysql' -> `mysql-5.6.38-linux-glibc2.12-x86_64/'

4)Start the older MySQL server, using the new data directory

把新的my.cnf配置文件配置一份,然后修改一下my.cnf中的datadir目录指向旧的数据目录,然后执行初始化操作

[root@mysqlmaster01 local]# vim /etc/my.cnf

[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 2
query_cache_size= 16M
datadir=/data/mysql5.6_data/
innodb_log_file_size = 1G
log_error = error.log
skip_name_resolve = 1
bind_address = 10.2.11.226
~

[root@mysqlmaster01 mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mysql5.6_data/   初始化mysql数据库到新的目录

2017-11-22 10:06:57 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2017-11-22 10:06:57 0 [Note] ./bin/mysqld (mysqld 5.6.38) starting as process 3353 ...
OK

Filling help tables...2017-11-22 10:08:27 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-11-22 10:08:27 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2017-11-22 10:08:27 0 [Note] ./bin/mysqld (mysqld 5.6.38) starting as process 3375 ...
OK

[root@mysqlmaster01 bin]# ./mysqld_safe --user=mysql --datadir=/data/mysql5.6_data/ &
[3] 5970
[root@mysqlmaster01 bin]# 171122 10:31:02 mysqld_safe Logging to '/data/mysql5.6_data/error.log'.
171122 10:31:02 mysqld_safe A mysqld process already exists

[3] Exit 1 ./mysqld_safe --user=mysql --datadir=/data/mysql5.6_data/
[root@mysqlmaster01 bin]#
[root@mysqlmaster01 bin]# ss -tunlp|grep 3306
tcp LISTEN 0 128 10.2.11.226:3306 *:* users:(("mysqld",5945,22))
[root@mysqlmaster01 bin]# mysql -V
mysql Ver 14.14 Distrib 5.6.38, for linux-glibc2.12 (x86_64) using EditLine wrapper

如果运行mysql -u root 提示要输入密码,操作如下

先正常关闭mysqld服务,然后运行时,加--skip-grant-tables

[root@mysqlmaster01 bin]# ./mysqld_safe --user=mysql --datadir=/data/mysql5.6_data/ --skip-grant-tables &

mysql> update mysql.user set password=PASSWORD('Aa123456') where User='root';
Query OK, 0 rows affected (0.01 sec)
Rows matched: 0 Changed: 0 Warnings: 0

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

然后重启mysql

[root@mysqlmaster01 bin]# service mysqld start
Starting MySQL SUCCESS!
[root@mysqlmaster01 bin]# ss -tunlp|grep 3306
[root@mysqlmaster01 bin]#
[root@mysqlmaster01 bin]#
[root@mysqlmaster01 bin]# ss -tunlp|grep 3306
tcp LISTEN 0 128 10.2.11.226:3306 *:* users:(("mysqld",22339,22))

5)Load the dump file into the older MySQL server. For example:

[root@mysqlmaster01 bin]# ./mysql -u root -p < /root/downgrade.sql
Enter password:
ERROR 1726 (HY000) at line 202: Storage engine 'InnoDB' does not support system tables. [mysql.help_category]

6)Run mysql_upgrade. For example:

mysql_upgrade -u root -p

7)重新启动mysqld数据库

二、mysql_config_editor命令

[root@mysqlmaster01 mysql]# mysql_config_editor --help
mysql_config_editor Ver 1.0 Distrib 5.7.20, for linux-glibc2.12 on x86_64
Copyright (c) 2012, 2017, 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.

MySQL Configuration Utility.
Usage: mysql_config_editor [program options] [command [command options]]
-#, --debug[=#] This is a non-debug version. Catch this and exit.
-?, --help Display this help and exit.
-v, --verbose Write more information.
-V, --version Output version information and exit.

Variables (--variable-name=value)
and boolean options {FALSE|TRUE} Value (after reading options)
--------------------------------- ----------------------------------------
verbose FALSE

Where command can be any one of the following :
set [command options] Sets user name/password/host name/socket/port
for a given login path (section).
remove [command options] Remove a login path from the login file.
print [command options] Print all the options for a specified
login path.
reset [command options] Deletes the contents of the login file.
help Display this usage/help information.

[root@mysqlmaster01 mysql]# mysql_config_editor set -G vm1 -S /tmp/mysql.sock -uroot -p (新建一个vm1的标签)
Enter password:

[root@mysqlmaster01 mysql]# mysql_config_editor print --all (查看)
[vm1]
user = root
password = *****
socket = /tmp/mysql.sock

[root@mysqlmaster01 mysql]# mysql --help -vv|grep login
-u, --user=name User for login if not current user.
except for login file.
--login-path=# Read this path from the login file.

-rw-------. 1 root root 136 Nov 21 16:59 .mylogin.cnf (在root目录下会产生这个文件)

[root@mysqlmaster01 mysql]# mysql --login-path=vm1 (通过这种方式,不用输入密码)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.20 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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>

三)mysql配置参数

  • 从作用域上可以分为global和session
  • 从类型上可分为可修改和不可修改
  • 用户可以在线修改非只读参数
  • 只读参数只能通过配置文件修改并重启mysqld
  • 所有参数的修改都不是持久化的,服务器重启后失效,如果要永久生效,必须写到配置文件中

查看变量:

mysql> show global variables;

mysql> show global variables like 'slow%'; (like来进行匹配)
+---------------------+-----------------------------------------+
| Variable_name | Value |
+---------------------+-----------------------------------------+
| slow_launch_time | 2 |
| slow_query_log | ON |
| slow_query_log_file | /data/mysql_data/mysqlmaster01-slow.log |
+---------------------+-----------------------------------------+
3 rows in set (0.00 sec)

(每个版本的,参数基本都不一样)

mysql> set global slow_query_log = 'OFF'; (修改mysql配置参数,通过set命令)
Query OK, 0 rows affected (0.00 sec)

四)mysql用户权限问题

注意:删除所有用户名为空的用户,不允许密码为空的用户存在,管理员可以管理所有库的权限,开发只给响应库的权限

  • 根据用户名和IP来进行过滤
  • 查看mysql.user、mysql.db、mysql.tables_priv

mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| engine_cost |
| event |
| func |
| general_log |
| gtid_executed |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| server_cost |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
31 rows in set (0.00 sec)

mysql> select * from user where user='root' limit 1 \G
*************************** 1. row ***************************
Host: localhost
User: root
Select_priv: Y
Insert_priv: Y
Update_priv: Y
Delete_priv: Y
Create_priv: Y
Drop_priv: Y
Reload_priv: Y
Shutdown_priv: Y
Process_priv: Y
File_priv: Y
Grant_priv: Y
References_priv: Y
Index_priv: Y
Alter_priv: Y
Show_db_priv: Y
Super_priv: Y
Create_tmp_table_priv: Y
Lock_tables_priv: Y
Execute_priv: Y
Repl_slave_priv: Y
Repl_client_priv: Y
Create_view_priv: Y
Show_view_priv: Y
Create_routine_priv: Y
Alter_routine_priv: Y
Create_user_priv: Y
Event_priv: Y
Trigger_priv: Y
Create_tablespace_priv: Y
ssl_type:
ssl_cipher:
x509_issuer:
x509_subject:
max_questions: 0
max_updates: 0
max_connections: 0
max_user_connections: 0
plugin: mysql_native_password
authentication_string: *4A488726AE5A0B0F0DB967998EE12D87F25C9610
password_expired: N
password_last_changed: 2017-11-21 16:21:46
password_lifetime: NULL
account_locked: N
1 row in set (0.00 sec)

常用权限规划

SQL语句: select 、insert、update、delete、 index

存储过程: create routine、alter routine、execule

管理权限: super、reload、show database、shutdown、create database

官网:https://dev.mysql.com/doc/refman/5.7/en/privileges-provided.html (查看mysqld5.7有哪些些权限)

mysql> help grant
Name: 'GRANT'
Description:
Syntax:
GRANT
priv_type [(column_list)]
[, priv_type [(column_list)]] ...
ON [object_type] priv_level
TO user [auth_option] [, user [auth_option]] ...
[REQUIRE {NONE | tls_option [[AND] tls_option] ...}]
[WITH {GRANT OPTION | resource_option} ...]

GRANT PROXY ON user
TO user [, user] ...
[WITH GRANT OPTION]

object_type: {
TABLE
| FUNCTION
| PROCEDURE
}

priv_level: {
*
| *.*
| db_name.*
| db_name.tbl_name
| tbl_name
| db_name.routine_name
}

user:
(see http://dev.mysql.com/doc/refman/5.6/en/account-names.html)

auth_option: {
IDENTIFIED BY 'auth_string'
| IDENTIFIED BY PASSWORD 'hash_string'
| IDENTIFIED WITH auth_plugin
| IDENTIFIED WITH auth_plugin AS 'hash_string'
}

tls_option: {
SSL
| X509
| CIPHER 'cipher'
| ISSUER 'issuer'
| SUBJECT 'subject'
}

resource_option: {
| MAX_QUERIES_PER_HOUR count
| MAX_UPDATES_PER_HOUR count
| MAX_CONNECTIONS_PER_HOUR count
| MAX_USER_CONNECTIONS count
}

用户权限授权

官网:https://dev.mysql.com/doc/refman/5.7/en/grant.html

mysql> grant all on *.* to 'senior_dba'@'127.0.0.1' identified by 'Aa123456' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)

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

说明:授权senior_dba从127.0.0.1登录,拥有所有权限,并且该用户还可以授权其他用户

[root@mysqlmaster01 ~]# mysql -u senior_dba -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.7.20 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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> grant select,insert,update,delete on wpdb.* to 'dev'@'10.2.18.%' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> grant select on wpdb.wp_report to 'report'@'10.2.18.%' identified by '123456';

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

错误1:

在升级MySQL5.5过程中,执行/usr/local/mysql/bin/mysql_upgrade

提示:

Looking for 'mysql' in: /usr/local/mysql/bin/mysql
Looking for 'mysqlcheck' in: /usr/local/mysql/bin/mysqlcheck
Running 'mysqlcheck'...
/usr/local/mysql/bin/mysqlcheck: Got error: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FOR UPGRADE' at line 1 when executing 'CHECK TABLE ... FOR UPGRADE'
FATAL ERROR: Upgrade failed
 启用 --skip-grant-tables参数避开检查,先启动再说 /usr/local/mysql/bin/mysqld --datadir=/usr/local/mysql/var/ --user=mysql --skip-grant-tables &
然后配置my.cnf参数,以适合新版本的

mysql软件升降级及配置参数的更多相关文章

  1. 影响MySQL性能的五大配置参数

    我们今天主要和大家分享的是对MySQL性能影响关系紧密的五大配置参数,以下就是文章的具体内容描述,希望会给你带来一些帮助在此方面. 以下的文章主要是对MySQL性能影响关系紧密的五大配置参数的介绍,我 ...

  2. Mysql数据库操作系统及配置参数优化

    数据库结构优化 表的水平拆分常用的水平拆分方法为:1.对 customer_id进行 hash运算,如果要拆分成5个表 则使用mod(customer_id,5)取出0-4个值2.针对不同的 hash ...

  3. MySQL性能的五大配置参数(内存参数)

    内存参数: 存储引擎/共享日志缓冲区,缓冲区池 innodb_buffer_pool_sizeinnodb_additional_mem_pool_sizeinnodb_log_buffer_size ...

  4. MySQL Cluster 7.3.5 集群配置参数优化(优化篇)

    按照前面的教程:MySQL Cluster 7.3.5 集群配置实例(入门篇),可快速搭建起基础版的MySQL Cluster集群,但是在生成环境中,还是有很多问题的,即配置参数需要优化下, 当前生产 ...

  5. MySQL性能优化之max_connections配置参数浅析

    这篇文章主要介绍了MySQL性能优化之max_connections配置参数浅析,本文着重讲解了3种配置max_connections参数的方法,需要的朋友可以参考下 MySQL的max_connec ...

  6. MySql配置参数很全的Mysql配置参数说明

    MySql配置参数 很全的Mysql配置参数说明 1. back_log 指定MySQL可能的连接数量.当MySQL主线程在很短的时间内得到非常多的连接请求,该参数就起作用,之后主线程花些时间(尽管很 ...

  7. 通过查看mysql 配置参数、状态来优化你的mysql

    mysql的监控方法大致分为两类: 1.连接到mysql数据库内部,使用show status,show variables,flush status 来查看mysql的各种性能指标. 2. 直接使用 ...

  8. mysql 通过查看mysql 配置参数、状态来优化你的mysql

    我把MYISAM改成了INNODB,数据库对CPU方面的占用变小很多' mysql的监控方法大致分为两类: 1.连接到mysql数据库内部,使用show status,show variables,f ...

  9. Mysql配置参数sync_binlog说明

    Mysql配置参数sync_binlog说明 mysql> select version(); +-----------+ | version() | +-----------+ | | +-- ...

随机推荐

  1. B进制星球(多进制 高精加)

    https://www.luogu.org/problemnew/show/P1604 B(2<=B<=36)进制计数.编写实现B进制加法的程序. 输入输出格式 输入格式: 共3行第1行: ...

  2. PHP基础知识 - session和cookie的区别

    session:存储用户访问全局的唯一变量,在服务器上的PHP指定的目录中(session_dir)的位置进行存放 修改session的生存时间: (1)修改PHP.ini配置    修改php.in ...

  3. sql语句中的占位符?有什么作用

    String sql = "SELECT userid,name FROM tuser WHERE userid=? AND password=?" ; pstmt = conn. ...

  4. Lua 学习之基础篇六<Lua IO 库>

    引言 I/O 库提供了两套不同风格的文件处理接口. 第一种风格使用隐式的文件句柄: 它提供设置默认输入文件及默认输出文件的操作, 所有的输入输出操作都针对这些默认文件. 第二种风格使用显式的文件句柄. ...

  5. EMF保存CDATA

    /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated NOT */ public String ...

  6. ACM-ICPC 2018 沈阳赛区现场赛 K. Let the Flames Begin (约瑟夫环问题)

    题目链接: 题意:有 n 个人围成一个圈,从 1 开始报到第 k 个人出环,问第 m 个出环的人是谁,n.m.k <= 1e18 且 min(m,k)<= 2e6. 题解:容易得出O(m) ...

  7. C# Parallel 使用

    ParallelLoopResult result = Parallel.For(, , i => { Console.WriteLine("{0}, task: {1}, threa ...

  8. 004_linuxC++之_函数的重载

    (一)源码下载 (一) 函数的重载:同一个命名函数,通过传入参数的不同,调用不一样的函数 上面程序的运行结果: (二)函数只能通过参数的不一样重载函数,不能通过返回参数的不一样重载函数 运行结果报错 ...

  9. 009_STM32程序移植之_内部falsh

    flash  模拟  EEPROM  实验 1. 测试环境:STM32C8T6 2. 测试接口: 3. 串口使用串口一,波特率9600 单片机引脚------------CH340引脚 VCC---- ...

  10. 10 | MySQL为什么有时候会选错索引?

    前面我们介绍过索引,你已经知道了在MySQL中一张表其实是可以支持多个索引的.但是,你写SQL语句的时候,并没有主动指定使用哪个索引.也就是说,使用哪个索引是由MySQL来确定的. 不知道你有没有碰到 ...