RHEL7.6_mysql5.x_8.x编译安装
1.编译安装mysql5.5
1.1下载mysql5.5
下载mysql5.5地址:https://downloads.mysql.com/archives/community/
1.2 上载mysql5.5
解压mysql5.5到安装目录,如下:
[root@tidb01 mysql5.5]# pwd /home/mysql5.5 [root@tidb01 mysql5.5]# ls mysql mysql-5.5.62 mysql-5.5.62.tar.gz [root@tidb01 mysql5.5]# |
1.3 解压mysql5.5
解压mysql5.5,如下命令。
[root@tidb01 mysql5.5]# tar -zxvf mysql-5.5.62.tar.gz |
1.4 下载cmake
下载cmake,如下:
下载地址:https://cmake.org/files/
1.5 编译安装cmake
1.5.1 解压cmake
解压cmake,如下:
[root@tidb01 mysql5.5]# tar -zxvf cmake-3.21.0-linux-x86_64.tar.gz [root@tidb02 mysql5.5]# tar -zxvf cmake-3.21.0-linux-x86_64.tar.gz [root@tidb03 mysql5.5]# tar -zxvf cmake-3.21.0-linux-x86_64.tar.gz |
1.5.2 设置cmake
编译安装cmake,如下:
[root@tidb01 mysql5.5]# mkdir /usr/local/cmake [root@tidb01 mysql5.5]# cp -r cmake-3.21.0-linux-x86_64 /usr/local/cmake export PATH=/usr/local/cmake/bin/:$PATH [root@tidb01 mysql5.5]# source /etc/profile [root@tidb01 mysql5.5]# which cmake /usr/local/cmake/bin/cmake [root@tidb01 mysql5.5]#s |
1.6 编译安装mysql5.5
编译安装mysql5.5,如下:
[root@tidb01 mysql5.5]# mkdir -p /home/mysql5.5/mysql/data [root@tidb01 mysql5.5]# cd mysql-5.5.62/ [root@tidb01 mysql-5.5.62]# pwd /home/mysql5.5/mysql-5.5.62 [root@tidb01 mysql-5.5.62]# |
编译安装mysql5.5,如下:
cmake -DCMAKE_INSTALL_PREFIX=/home/mysql5.5/mysql \ -DMYSQL_UNIX_ADDR=/home/mysql5.5/mysql/mysql.sock \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_MEMORY_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DENABLED_LOCAL_INFILE=1 \ -DMYSQL_DATADIR=/home/mysql5.5/mysql/data \ -DMYSQL_USER=mysql \ -DMYSQL_TCP_PORT=3306 |
报错如下:
-- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH) CMake Error at cmake/readline.cmake:83 (MESSAGE): Curses library not found. Please install appropriate package, remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel. Call Stack (most recent call first): cmake/readline.cmake:118 (FIND_CURSES) cmake/readline.cmake:214 (MYSQL_USE_BUNDLED_READLINE) CMakeLists.txt:394 (MYSQL_CHECK_READLINE) |
安装,如下:
[root@tidb01 mysql-5.5.62]# yum install ncurses-devel |
编译OK,执行安装:
make && make install |
同理,编译安装mysql5.6,如下:
cmake -DCMAKE_INSTALL_PREFIX=/home/mysql5.6/mysql \ -DMYSQL_UNIX_ADDR=/home/mysql5.6/mysql/mysql.sock \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_MEMORY_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DENABLED_LOCAL_INFILE=1 \ -DMYSQL_DATADIR=/home/mysql5.6/mysql/data \ -DMYSQL_USER=mysql \ -DMYSQL_TCP_PORT=3306 |
1.7 执行数据库初始化
执行数据库初始化,如下:
[mysql5.5@tidb01 mysql]$ scripts/mysql_install_db --user=mysql5.5 --basedir=/home/mysql5.5/mysql --datadir=/home/mysql5.5/mysql/data |
执行结果,如下:
[mysql5.5@tidb01 mysql]$ scripts/mysql_install_db --user=mysql5.5 --basedir=/home/mysql5.5/mysql --datadir=/home/mysql5.5/mysql/data Installing MySQL system tables... 210823 0:51:47 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap. 210823 0:51:47 [Note] /home/mysql5.5/mysql/bin/mysqld (mysqld 5.5.62-log) starting as process 54657 ... OK Filling help tables... 210823 0:51:48 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap. 210823 0:51:48 [Note] /home/mysql5.5/mysql/bin/mysqld (mysqld 5.5.62-log) starting as process 54664 ... OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /home/mysql5.5/mysql/bin/mysqladmin -u root password 'new-password' /home/mysql5.5/mysql/bin/mysqladmin -u root -h tidb01.dev.com password 'new-password' Alternatively you can run: /home/mysql5.5/mysql/bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd /home/mysql5.5/mysql ; /home/mysql5.5/mysql/bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd /home/mysql5.5/mysql/mysql-test ; perl mysql-test-run.pl Please report any problems at http://bugs.mysql.com/ [mysql5.5@tidb01 mysql]$ |
1.8 设置mysql开机启动
cp support-files/mysql.server /etc/init.d/mysql chmod 755/etc/init.d/mysql chkconfig mysql on [root@tidb01 mysql]# chown -R mysql5.5:mysql5.5 /etc/init.d/mysql |
执行如下:
[root@tidb01 mysql5.5]# cd /home/mysql5.5/mysql [root@tidb01 mysql]# cp support-files/mysql.server /etc/init.d/mysql [root@tidb01 mysql]# chmod 755 /etc/init.d/mysql [root@tidb01 mysql]# chown -R mysql5.5:mysql5.5 /etc/init.d/mysql [root@tidb01 mysql]# [root@tidb01 mysql]# chkconfig mysql on [root@tidb01 mysql]# |
1.9 设置mysql环境变量
设置mysql环境变量,执行如下:
[mysql5.5@tidb01 ~]$ vi .bash_profile [mysql5.5@tidb01 ~]$ source .bash_profile [mysql5.5@tidb01 ~]$ cat .bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/.local/bin:$HOME/bin export PATH export MYSQL_HOME=/home/mysql5.5/mysql export PATH=$MYSQL_HOME/bin:$PATH [mysql5.5@tidb01 ~]$ |
1.10 配置文件.my.cnf
mysql配置文件的执行顺序,如下:
|
拷贝配置文件,如下:
[mysql5.5@tidb01 mysql]$ cp support-files/my-medium.cnf ~/.my.cnf [mysql5.5@tidb01 mysql]$ |
1.11 启动mysql数据库
启动mysql数据库,如下:
cd /home/mysql5.5/mysql ; /home/mysql5.5/mysql/bin/mysqld_safe & |
执行启动:
[mysql5.5@tidb01 ~]$ /etc/init.d/mysql start Starting MySQL..[ OK ] [mysql5.5@tidb01 ~]$ ps -ef|grep mysql root 56468 52809 0 01:04 pts/0 00:00:00 su - mysql5.5 mysql5.5 56469 56468 0 01:04 pts/0 00:00:00 -bash mysql5.5 56694 1 0 01:05 pts/0 00:00:00 /bin/sh /home/mysql5.5/mysql/bin/mysqld_safe --datadir=/home/mysql5.5/mysql/data --pid-file=/home/mysql5.5/mysql/data/tidb01.dev.com.pid mysql5.5 56959 56694 1 01:05 pts/0 00:00:00 /home/mysql5.5/mysql/bin/mysqld --basedir=/home/mysql5.5/mysql --datadir=/home/mysql5.5/mysql/data --plugin-dir=/home/mysql5.5/mysql/lib/plugin --log-error=tidb01.dev.com.err --pid-file=/home/mysql5.5/mysql/data/tidb01.dev.com.pid --socket=/home/mysql5.5/mysql/mysql.sock --port=3306 mysql5.5 57001 56469 0 01:06 pts/0 00:00:00 ps -ef mysql5.5 57002 56469 0 01:06 pts/0 00:00:00 grep --color=auto mysql [mysql5.5@tidb01 ~]$ |
1.12 修改root密码
修改root密码,如下:
[mysql5.5@tidb01 ~]$ mysqladmin -u root password 'passwd123456' |
还有另外一种修改密码方法,如下:
删除本机匿名连接的空密码帐号 use mysql; update user set password='root' where user = '127.0.0.1'; //给本地账户设置一个密码 delete from user where password=""; //删除空密码 flush privileges; //使设置生效 |
实际执行,如下:
mysql> update user set password='root' where host = '127.0.0.1'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> |
1.13 登录mysql
登录mysql,如下:
[mysql5.5@tidb01 ~]$ mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.5.62-log Source distribution 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> |
查看mysql内置用户,如下:
mysql> use mysql Database changed mysql> select host,user from user; +------------------+------+ | host | user | +------------------+------+ | 127.0.0.1 | root | | ::1 | root | | localhost | | | localhost | root | | tidb01.dev.com | | | tidb01.dev.com | root | +------------------+------+ 6 rows in set (0.00 sec) mysql> |
1.14 创建mysql连接账号
创建mysql连接账号,如下:
grant来创建用户:
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.5/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 } The GRANT statement grants privileges to MySQL user accounts. GRANT also serves to specify other account characteristics such as use of secure connections and limits on access to server resources. To use GRANT, you must have the GRANT OPTION privilege, and you must have the privileges that you are granting. When the read_only system variable is enabled, GRANT additionally requires the SUPER privilege. The REVOKE statement is related to GRANT and enables administrators to remove account privileges. See [HELP REVOKE]. Each account name uses the format described in http://dev.mysql.com/doc/refman/5.5/en/account-names.html. For example: GRANT ALL ON db1.* TO 'jeffrey'@'localhost'; The host name part of the account, if omitted, defaults to '%'. Normally, a database administrator first uses CREATE USER to create an account, then GRANT to define its privileges and characteristics. For example: CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'password'; GRANT ALL ON db1.* TO 'jeffrey'@'localhost'; GRANT SELECT ON db2.invoice TO 'jeffrey'@'localhost'; GRANT USAGE ON *.* TO 'jeffrey'@'localhost' WITH MAX_QUERIES_PER_HOUR 90; *Note*: Examples shown here include no IDENTIFIED clause. It is assumed that you establish passwords with CREATE USER at account-creation time to avoid creating insecure accounts. If an account named in a GRANT statement does not already exist, GRANT may create it under the conditions described later in the discussion of the NO_AUTO_CREATE_USER SQL mode. From the mysql program, GRANT responds with Query OK, 0 rows affected when executed successfully. To determine what privileges result from the operation, use SHOW GRANTS. See [HELP SHOW GRANTS]. URL: http://dev.mysql.com/doc/refman/5.5/en/grant.html |
说明【USAGE权限】:
mysql数据库用户在创建的时候就会赋予USAGE权限,这个权限很小,几乎为0。 只能连接数据库和查询information_schema的权限。 |
创建超级账号,如下:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.2.%'IDENTIFIED BY 'passwd123456'WITH GRANT OPTION; |
实际执行,如下:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@' 192.168.2.%' IDENTIFIED BY 'passwd123456' WITH GRANT OPTION; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> |
2.编译安装mysql5.6
过程与编译安装mysql5.5类似。
2.6 编译安装mysql5.6
同理,编译安装mysql5.6,如下:
cmake -DCMAKE_INSTALL_PREFIX=/home/mysql5.6/mysql \ -DMYSQL_UNIX_ADDR=/home/mysql5.6/mysql/mysql.sock \ -DSYSCONFDIR=/home/mysql5.6/mysql/etc \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_MEMORY_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DENABLED_LOCAL_INFILE=1 \ -DMYSQL_DATADIR=/home/mysql5.6/mysql/data \ -DMYSQL_USER=mysql \ -DMYSQL_TCP_PORT=3306 |
报错,如下:
CMake Warning (dev) at /usr/local/cmake/share/cmake-3.21/Modules/CheckIncludeFile.cmake:82 (message): Policy CMP0075 is not set: Include file check macros honor CMAKE_REQUIRED_LIBRARIES. Run "cmake --help-policy CMP0075" for policy details. Use the cmake_policy command to set the policy and suppress this warning. CMAKE_REQUIRED_LIBRARIES is set to: m;crypt;dl;-lpthread For compatibility with CMake 3.11 and below this check is ignoring it. Call Stack (most recent call first): zlib/CMakeLists.txt:73 (check_include_file) This warning is for project developers. Use -Wno-dev to suppress it. -- Looking for unistd.h - found -- OPENSSL_INCLUDE_DIR = OPENSSL_INCLUDE_DIR-NOTFOUND -- OPENSSL_LIBRARY = OPENSSL_LIBRARY-NOTFOUND -- CRYPTO_LIBRARY = CRYPTO_LIBRARY-NOTFOUND -- OPENSSL_MAJOR_VERSION = -- OPENSSL_MINOR_VERSION = -- OPENSSL_FIX_VERSION = -- Looking for SHA512_DIGEST_LENGTH -- Looking for SHA512_DIGEST_LENGTH - not found -- Cannot find appropriate system libraries for WITH_SSL=system. Make sure you have specified a supported SSL version. Valid options are : system (use the OS openssl library), yes (synonym for system), </path/to/custom/openssl/installation> CMake Error at cmake/ssl.cmake:66 (MESSAGE): Please install the appropriate openssl developer package. Call Stack (most recent call first): cmake/ssl.cmake:260 (FATAL_SSL_NOT_FOUND_ERROR) CMakeLists.txt:483 (MYSQL_CHECK_SSL) -- Configuring incomplete, errors occurred! See also "/home/mysql5.6/mysql-5.6.51/CMakeFiles/CMakeOutput.log". See also "/home/mysql5.6/mysql-5.6.51/CMakeFiles/CMakeError.log" |
安装相关依赖包,执行如下:
[root@tidb02 mysql-5.6.51]# yum -y install make gcc-c++ cmake bison-devel ncurses-devel |
安装,执行如下:
[root@tidb02 mysql-5.6.51]# yum -y install openssl-devel |
执行安装,如下:
[root@tidb02 mysql-5.6.51]#make && make install |
2.7配置文件.my.cnf
授权,如下:
[root@tidb02 mysql5.6]# chown -R mysql5.6:mysql5.6 mysql
执行拷贝配文件,如下:
[mysql5.6@tidb02 mysql]$ cp support-files/my-medium.cnf ~/.my.cnf cp: cannot stat ‘support-files/my-medium.cnf’: No such file or directory [mysql5.6@tidb02 mysql]$ ls -alt support-files/ total 32 drwxr-xr-x 13 mysql5.6 mysql5.6 191 Aug 23 01:58 .. drwxr-xr-x 2 mysql5.6 mysql5.6 136 Aug 23 01:58 . -rwxr-xr-x 1 mysql5.6 mysql5.6 1153 Aug 23 01:32 binary-configure -rw-r--r-- 1 mysql5.6 mysql5.6 1126 Aug 23 01:32 my-default.cnf -rwxr-xr-x 1 mysql5.6 mysql5.6 1061 Aug 23 01:32 mysqld_multi.server -rwxr-xr-x 1 mysql5.6 mysql5.6 914 Aug 23 01:32 mysql-log-rotate -rwxr-xr-x 1 mysql5.6 mysql5.6 10589 Aug 23 01:32 mysql.server -rw-r--r-- 1 mysql5.6 mysql5.6 773 Jan 5 2021 magic [mysql5.6@tidb02 mysql]$ |
注意:从mysql5.6以及之后版本,在/etc目录下会存在一个my.cnf,需要将此文件更名为其他的名字。
[root@tidb02 mysql5.6]# ls -alt /etc/my.cnf -rw-r--r--. 1 root root 570 Jun 5 2018 /etc/my.cnf [root@tidb02 mysql5.6]# date Mon Aug 23 02:04:02 CST 2021 [root@tidb02 mysql5.6]# mv /etc/my.cnf /etc/my.cnf_bak [root@tidb02 mysql5.6]# |
执行如下:
[mysql5.6@tidb02 mysql]$ cp support-files/my-default.cnf ~/.my.cnf [mysql5.6@tidb02 mysql]$ |
设置相关参数,如下:
[client] port = 3306 socket = /home/mysql5.6/mysql/mysql.sock [mysqld] port = 3306 socket =/home/mysql5.6/mysql/mysql.sock user = mysql5.6 basedir = /home/mysql5.6/mysql datadir = /home/mysql5.6/mysql/data pid-file = /home/mysql5.6/mysql/mysql.pid log_error = /home/mysql5.6/mysql/mysql-error.log slow_query_log = 1 long_query_time = 1 slow_query_log_file =/home/mysql5.6/mysql/mysql-slow.log skip-external-locking key_buffer_size = 32M max_allowed_packet = 1024M table_open_cache = 128 sort_buffer_size = 768K net_buffer_length = 8K read_buffer_size = 768K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M thread_cache_size = 16 query_cache_size = 16M tmp_table_size = 32M performance_schema_max_table_instances = 1000 explicit_defaults_for_timestamp = true #skip-networking max_connections = 500 max_connect_errors = 100 open_files_limit = 65535 log_bin=mysql-bin binlog_format=mixed server_id = 232 expire_logs_days = 10 early-plugin-load = "" default_storage_engine = InnoDB innodb_file_per_table = 1 innodb_buffer_pool_size = 128M innodb_log_file_size = 32M innodb_log_buffer_size = 8M innodb_flush_log_at_trx_commit = 1 innodb_lock_wait_timeout = 50 [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash [myisamchk] key_buffer_size = 32M sort_buffer_size = 768K read_buffer = 2M write_buffer = 2M |
2.8执行数据库初始化
执行数据库初始化,如下:
[mysql5.6@tidb02 mysql]$ scripts/mysql_install_db --user=mysql5.6 --basedir=/home/mysql5.6/mysql --datadir=/home/mysql5.6/mysql/data Installing MySQL system tables...2021-08-24 00:27:08 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2021-08-24 00:27:08 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap. 2021-08-24 00:27:08 0 [Note] /home/mysql5.6/mysql/bin/mysqld (mysqld 5.6.51) starting as process 109347 ... 2021-08-24 00:27:08 109347 [Note] InnoDB: Using atomics to ref count buffer pool pages 2021-08-24 00:27:08 109347 [Note] InnoDB: The InnoDB memory heap is disabled 2021-08-24 00:27:08 109347 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2021-08-24 00:27:08 109347 [Note] InnoDB: Memory barrier is not used 2021-08-24 00:27:08 109347 [Note] InnoDB: Compressed tables use zlib 1.2.11 2021-08-24 00:27:08 109347 [Note] InnoDB: Using Linux native AIO 2021-08-24 00:27:08 109347 [Note] InnoDB: Using CPU crc32 instructions 2021-08-24 00:27:08 109347 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2021-08-24 00:27:08 109347 [Note] InnoDB: Completed initialization of buffer pool 2021-08-24 00:27:08 109347 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created! 2021-08-24 00:27:08 109347 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB 2021-08-24 00:27:08 109347 [Note] InnoDB: Database physically writes the file full: wait... 2021-08-24 00:27:08 109347 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB 2021-08-24 00:27:08 109347 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB 2021-08-24 00:27:08 109347 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0 2021-08-24 00:27:08 109347 [Warning] InnoDB: New log files created, LSN=45781 2021-08-24 00:27:08 109347 [Note] InnoDB: Doublewrite buffer not found: creating new 2021-08-24 00:27:08 109347 [Note] InnoDB: Doublewrite buffer created 2021-08-24 00:27:08 109347 [Note] InnoDB: 128 rollback segment(s) are active. 2021-08-24 00:27:08 109347 [Warning] InnoDB: Creating foreign key constraint system tables. 2021-08-24 00:27:08 109347 [Note] InnoDB: Foreign key constraint system tables created 2021-08-24 00:27:08 109347 [Note] InnoDB: Creating tablespace and datafile system tables. 2021-08-24 00:27:08 109347 [Note] InnoDB: Tablespace and datafile system tables created. 2021-08-24 00:27:08 109347 [Note] InnoDB: Waiting for purge to start 2021-08-24 00:27:08 109347 [Note] InnoDB: 5.6.51 started; log sequence number 0 2021-08-24 00:27:08 109347 [Note] RSA private key file not found: /home/mysql5.6/mysql/data//private_key.pem. Some authentication plugins will not work. 2021-08-24 00:27:08 109347 [Note] RSA public key file not found: /home/mysql5.6/mysql/data//public_key.pem. Some authentication plugins will not work. 2021-08-24 00:27:08 109347 [Note] Binlog end 2021-08-24 00:27:08 109347 [Note] InnoDB: FTS optimize thread exiting. 2021-08-24 00:27:08 109347 [Note] InnoDB: Starting shutdown... 2021-08-24 00:27:10 109347 [Note] InnoDB: Shutdown completed; log sequence number 1625977 OK Filling help tables...2021-08-24 00:27:10 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2021-08-24 00:27:10 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap. 2021-08-24 00:27:10 0 [Note] /home/mysql5.6/mysql/bin/mysqld (mysqld 5.6.51) starting as process 109371 ... 2021-08-24 00:27:10 109371 [Note] InnoDB: Using atomics to ref count buffer pool pages 2021-08-24 00:27:10 109371 [Note] InnoDB: The InnoDB memory heap is disabled 2021-08-24 00:27:10 109371 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2021-08-24 00:27:10 109371 [Note] InnoDB: Memory barrier is not used 2021-08-24 00:27:10 109371 [Note] InnoDB: Compressed tables use zlib 1.2.11 2021-08-24 00:27:10 109371 [Note] InnoDB: Using Linux native AIO 2021-08-24 00:27:10 109371 [Note] InnoDB: Using CPU crc32 instructions 2021-08-24 00:27:10 109371 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2021-08-24 00:27:10 109371 [Note] InnoDB: Completed initialization of buffer pool 2021-08-24 00:27:10 109371 [Note] InnoDB: Highest supported file format is Barracuda. 2021-08-24 00:27:10 109371 [Note] InnoDB: 128 rollback segment(s) are active. 2021-08-24 00:27:10 109371 [Note] InnoDB: Waiting for purge to start 2021-08-24 00:27:10 109371 [Note] InnoDB: 5.6.51 started; log sequence number 1625977 2021-08-24 00:27:10 109371 [Note] RSA private key file not found: /home/mysql5.6/mysql/data//private_key.pem. Some authentication plugins will not work. 2021-08-24 00:27:10 109371 [Note] RSA public key file not found: /home/mysql5.6/mysql/data//public_key.pem. Some authentication plugins will not work. 2021-08-24 00:27:10 109371 [Note] Binlog end 2021-08-24 00:27:10 109371 [Note] InnoDB: FTS optimize thread exiting. 2021-08-24 00:27:10 109371 [Note] InnoDB: Starting shutdown... 2021-08-24 00:27:12 109371 [Note] InnoDB: Shutdown completed; log sequence number 1625987 OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /home/mysql5.6/mysql/bin/mysqladmin -u root password 'new-password' /home/mysql5.6/mysql/bin/mysqladmin -u root -h tidb02.dev.com password 'new-password' Alternatively you can run: /home/mysql5.6/mysql/bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd . ; /home/mysql5.6/mysql/bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd mysql-test ; perl mysql-test-run.pl Please report any problems at http://bugs.mysql.com/ The latest information about MySQL is available on the web at http://www.mysql.com Support MySQL by buying support/licenses at http://shop.mysql.com New default config file was created as /home/mysql5.6/mysql/my.cnf and will be used by default by the server when you start it. You may edit this file to change server settings [mysql5.6@tidb02 mysql]$ |
2.9设置mysql开机启动
执行如下:
[root@tidb02 mysql5.6]# cd /home/mysql5.6/mysql [root@tidb02 mysql]# pwd /home/mysql5.6/mysql [root@tidb02 mysql]# ls bin data docs include lib LICENSE man my.cnf mysql-error.log mysql-test README scripts share sql-bench support-files [root@tidb02 mysql]# cp support-files/mysql.server /etc/init.d/mysql [root@tidb02 mysql]# chmod 755 /etc/init.d/mysql [root@tidb02 mysql]# chown -R mysql5.6:mysql5.6 /etc/init.d/mysql [root@tidb02 mysql]# chkconfig mysql on [root@tidb02 mysql]# |
2.10设置mysql环境变量
设置mysql环境变量,执行如下:
[mysql5.6@tidb02 ~]$ vi .bash_profile [mysql5.6@tidb02 ~]$ source .bash_profile [mysql5.6@tidb02 ~]$ cat .bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/.local/bin:$HOME/bin export PATH export MYSQL_HOME=/home/mysql5.6/mysql export PATH=$MYSQL_HOME/bin:$PATH [mysql5.5@tidb02 ~]$ |
3.11配置文件.my.cnf
重命名默认配置文件,如下:
[root@tidb02 mysql]# mv /etc/my.cnf /etc/my.cnf_bak
2.12启动mysql数据库
启动mysql数据库,如下:
cd /home/mysql5.6/mysql ; /home/mysql5.6/mysql/bin/mysqld_safe & |
执行启动:
[mysql5.6@tidb02 mysql]$ /etc/init.d/mysql start Starting MySQL.[ OK ] [mysql5.6@tidb02 mysql]$ ps -ef|grep mysql root 109275 93978 0 00:26 pts/0 00:00:00 su - mysql5.6 mysql5.6 109276 109275 0 00:26 pts/0 00:00:00 -bash mysql5.6 110150 1 0 00:39 pts/0 00:00:00 /bin/sh /home/mysql5.6/mysql/bin/mysqld_safe --datadir=/home/mysql5.6/mysql/data --pid-file=/home/mysql5.6/mysql/data/tidb02.dev.com.pid mysql5.6 110252 110150 2 00:39 pts/0 00:00:00 /home/mysql5.6/mysql/bin/mysqld --basedir=/home/mysql5.6/mysql --datadir=/home/mysql5.6/mysql/data --plugin-dir=/home/mysql5.6/mysql/lib/plugin --log-error=tidb02.dev.com.err --pid-file=/home/mysql5.6/mysql/data/tidb02.dev.com.pid mysql5.6 110322 109276 0 00:40 pts/0 00:00:00 ps -ef mysql5.6 110323 109276 0 00:40 pts/0 00:00:00 grep --color=auto mysql [mysql5.6@tidb02 mysql]$ |
2.13修改root密码
修改root密码,如下:
[mysql5.6@tidb02 mysql]$ mysqladmin -u root password 'passwd123456' Warning: Using a password on the command line interface can be insecure. [mysql5.6@tidb02 mysql]$ |
还有另外一种修改密码方法,如下:
删除本机匿名连接的空密码帐号 use mysql; update user set password='root' where user = '127.0.0.1'; //给本地账户设置一个密码 delete from user where password=""; //删除空密码 flush privileges; //使设置生效 |
实际执行,如下:
mysql> update user set password='root' where host = '127.0.0.1'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> |
2.14登录mysql
登录mysql,如下:
[mysql5.6@tidb02 mysql]$ mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.6.51 Source distribution Copyright (c) 2000, 2021, 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内置用户,如下:
mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.00 sec) mysql> select host,user from user; +------------------+------+ | host | user | +------------------+------+ | 127.0.0.1 | root | | ::1 | root | | localhost | | | localhost | root | | tidb02.dev.com | | | tidb02.dev.com | root | +------------------+------+ 6 rows in set (0.00 sec) mysql> |
2.15创建mysql连接账号
创建超级账号,如下:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.2.%'IDENTIFIED BY 'passwd123456'WITH GRANT OPTION; |
实际执行,如下:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@' 192.168.2.%' IDENTIFIED BY 'passwd123456' WITH GRANT OPTION; Query OK, 0 rows affected (0.00 sec) mysql> |
3. 编译安装mysql5.7
3.5 安装boot
下载: http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
也可以直接下载带boot的mysql5.7,如下:
正在上传…重新上传取消
解压:
[root@tidb03 mysql5.7]# tar -zxvf mysql-boost-5.7.34.tar.gz |
3.6 编译安装mysql5.7
同理,编译安装mysql5.6,如下:
cmake \ -DCMAKE_BUILD_TYPE=RelWithDebInfo \ -DCMAKE_INSTALL_PREFIX=/home/mysql5.7/mysql \ -DMYSQL_UNIX_ADDR=/home/mysql5.7/mysql/mysql.sock \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DMYSQL_DATADIR=/home/mysql5.7/mysql/data \ -DSYSCONFDIR=/home/mysql5.7/mysql/my.cnf \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DENABLE_DEBUG_SYNC=0 \ -DENABLED_LOCAL_INFILE=1 \ -DENABLED_PROFILING=1 \ -DMYSQL_TCP_PORT=3306 \ -DWITH_DEBUG=0 \ -DWITH_SSL=yes \ -DDOWNLOAD_BOOST=1 \ -DWITH_BOOST=boost |
报错,如下:
CMake Error at cmake/boost.cmake:88 (MESSAGE): You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory> This CMake script will look for boost in <directory>. If it is not there, it will download and unpack it (in that directory) for you. If you are inside a firewall, you may need to use an http proxy: export http_proxy=http://example.com:80 Call Stack (most recent call first): cmake/boost.cmake:245 (COULD_NOT_FIND_BOOST) CMakeLists.txt:522 (INCLUDE) -- Configuring incomplete, errors occurred! See also "/home/mysql5.7/mysql-5.7.34/CMakeFiles/CMakeOutput.log". See also "/home/mysql5.7/mysql-5.7.34/CMakeFiles/CMakeError.log". [root@tidb03 mysql-5.7.34]# which cmake CMake Warning: Manually-specified variables were not used by the project: MYSQL_USER WITH_MEMORY_STORAGE_ENGINE WITH_READLINE -- Build files have been written to: /home/mysql5.7/mysql-5.7.34 [root@tidb03 mysql-5.7.34]# |
安装相关依赖包,执行如下:
[root@tidb03 mysql-5.7.34]# yum -y install ncurses ncurses-devel openssl-devel bison gcc gcc-c++ make cmake |
执行安装,如下:
[root@tidb03 mysql-5.7.34]#make && make install |
3.7执行数据库初始化
执行授权,如下:
[root@tidb03 mysql5.7]# chown -R mysql5.7:mysql5.7 mysql |
执行数据库初始化,如下:
[root@tidb03 mysql]# ./bin/mysqld --initialize-insecure --user=mysql5.7 --basedir=/home/mysql5.7/mysql --datadir=/home/mysql5.7/mysql/data 2021-08-23T17:02:01.614593Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2021-08-23T17:02:01.961863Z 0 [Warning] InnoDB: New log files created, LSN=45790 2021-08-23T17:02:02.025245Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2021-08-23T17:02:02.081744Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: d5f0d979-0433-11ec-b82e-000c29708bf6. 2021-08-23T17:02:02.082654Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2021-08-23T17:02:02.334651Z 0 [Warning] CA certificate ca.pem is self signed. 2021-08-23T17:02:02.382139Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option. [root@tidb03 mysql]# |
3.8设置mysql开机启动
执行如下:
[root@tidb03 mysql5.7]# cd /home/mysql5.7/mysql [root@tidb03 mysql]# pwd /home/mysql5.7/mysql [root@tidb03 mysql]# ls bin data docs include lib LICENSE man mysql-test README README-test share support-files [root@tidb03 mysql]# cp support-files/mysql.server /etc/init.d/mysql [root@tidb03 mysql]# chmod 755 /etc/init.d/mysql [root@tidb03 mysql]# chown -R mysql5.7:mysql5.7 /etc/init.d/mysql [root@tidb03 mysql]# chkconfig mysql on [root@tidb03 mysql]# |
3.9设置mysql环境变量
设置mysql环境变量,执行如下:
[mysql5.7@tidb03 ~]$ vi .bash_profile [mysql5.7@tidb03 ~]$ source .bash_profile [mysql5.7@tidb03 ~]$ cat .bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/.local/bin:$HOME/bin export PATH export MYSQL_HOME=/home/mysql5.7/mysql export PATH=$MYSQL_HOME/bin:$PATH [mysql5.5@tidb02 ~]$ |
3.10配置文件.my.cnf
重命名默认配置文件,如下:
[root@tidb03 mysql]# mv /etc/my.cnf /etc/my.cnf_bak
3.11启动mysql数据库
启动mysql数据库,如下:
cd /home/mysql5.7/mysql ; /home/mysql5.7/mysql/bin/mysqld_safe & |
执行启动:
[root@tidb03 mysql]# su - mysql5.7 Last login: Tue Aug 24 01:09:47 CST 2021 on pts/0 [mysql5.7@tidb03 ~]$ /etc/init.d/mysql start Starting MySQL.[ OK ] [mysql5.7@tidb03 ~]$ ps -ef|grep mysql root 103595 86871 0 01:12 pts/0 00:00:00 su - mysql5.7 mysql5.7 103596 103595 0 01:12 pts/0 00:00:00 -bash mysql5.7 103653 1 0 01:12 pts/0 00:00:00 /bin/sh /home/mysql5.7/mysql/bin/mysqld_safe --datadir=/home/mysql5.7/mysql/data --pid-file=/home/mysql5.7/mysql/data/tidb03.dev.com.pid mysql5.7 103744 103653 0 01:12 pts/0 00:00:00 /home/mysql5.7/mysql/bin/mysqld --basedir=/home/mysql5.7/mysql --datadir=/home/mysql5.7/mysql/data --plugin-dir=/home/mysql5.7/mysql/lib/plugin --log-error=tidb03.dev.com.err --pid-file=/home/mysql5.7/mysql/data/tidb03.dev.com.pid mysql5.7 103832 103596 0 01:13 pts/0 00:00:00 ps -ef mysql5.7 103833 103596 0 01:13 pts/0 00:00:00 grep --color=auto mysql [mysql5.7@tidb03 ~]$ |
3.12修改root密码
修改root密码,如下:
[mysql5.7@tidb03 ~]$ mysqladmin -u root password 'passwd123456' mysqladmin: [Warning] Using a password on the command line interface can be insecure. Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety. [mysql5.7@tidb03 ~]$ |
还有另外一种修改密码方法,如下:
删除本机匿名连接的空密码帐号 use mysql; update user set password='root' where user = '127.0.0.1'; //给本地账户设置一个密码 delete from user where password=""; //删除空密码 flush privileges; //使设置生效 |
实际执行,如下:
mysql> update user set password='root' where host = '127.0.0.1'; ERROR 1054 (42S22): Unknown column 'password' in 'field list' mysql> |
再次修改密码,如下:
mysql> update user set authentication_string='root' where host = '127.0.0.1'; Query OK, 0 rows affected (0.00 sec) Rows matched: 0 Changed: 0 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> |
修改密码,如下:
mysql> update user set authentication_string=password('root') where host = '127.0.0.1'; Query OK, 0 rows affected, 1 warning (0.00 sec) Rows matched: 0 Changed: 0 Warnings: 1 mysql> |
3.13登录mysql
登录mysql,如下:
[mysql5.7@tidb03 ~]$ mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.7.34 Source distribution Copyright (c) 2000, 2021, Oracle and/or its affiliates. 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内置用户,如下:
mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.00 sec) mysql> select host,user from user; +------------------+------+ | host | user | +------------------+------+ | 127.0.0.1 | root | | ::1 | root | | localhost | | | localhost | root | | tidb02.dev.com | | | tidb02.dev.com | root | +------------------+------+ 6 rows in set (0.00 sec) mysql> |
3.14创建mysql连接账号
创建超级账号,如下:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.2.%'IDENTIFIED BY 'passwd123456'WITH GRANT OPTION; |
实际执行,如下:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@' 192.168.2.%' IDENTIFIED BY 'passwd123456' WITH GRANT OPTION; Query OK, 0 rows affected (0.00 sec) mysql> |
4. 忘记root修改密码的办法
4.1 停止mysql服务
停止mysql服务:
[mysql5.7@tidb03 ~]$ service mysql stop Shutting down MySQL..[ OK ] [mysql5.7@tidb03 ~]$ |
4.2 --skip-grant-tables模式启动mysql
--skip-grant-tables模式启动mysql,如下:
[mysql5.7@tidb03 ~]$ mysql/bin/mysqld_safe --skip-grant-tables 2021-08-23T17:29:32.806663Z mysqld_safe Logging to '/home/mysql5.7/mysql/data/tidb03.dev.com.err'. 2021-08-23T17:29:32.842213Z mysqld_safe Starting mysqld daemon with databases from /home/mysql5.7/mysql/data [mysql5.7@tidb03 ~]$ ps -ef|grep mysql root 103595 86871 0 01:12 pts/0 00:00:00 su - mysql5.7 mysql5.7 103596 103595 0 01:12 pts/0 00:00:00 -bash mysql5.7 104823 103596 0 01:29 pts/0 00:00:00 /bin/sh mysql/bin/mysqld_safe --skip-grant-tables mysql5.7 104901 104823 0 01:29 pts/0 00:00:00 /home/mysql5.7/mysql/bin/mysqld --basedir=/home/mysql5.7/mysql --datadir=/home/mysql5.7/mysql/data --plugin-dir=/home/mysql5.7/mysql/lib/plugin --skip-grant-tables --log-error=tidb03.dev.com.err --pid-file=tidb03.dev.com.pid mysql5.7 105051 103596 0 01:30 pts/0 00:00:00 ps -ef mysql5.7 105052 103596 0 01:30 pts/0 00:00:00 grep --color=auto mysql [mysql5.7@tidb03 ~]$ |
4.3 无密码登录mysql服务
无密码登录mysql服务,如下:
[mysql5.7@tidb03 ~]$ mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.34 Source distribution Copyright (c) 2000, 2021, Oracle and/or its affiliates. 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> |
4.4 修改root密码
5.6&以及之后版本修改root密码,如下:
mysql> update mysql.user set password=password('root') where user = 'root'; Query OK, 0 rows affected, 1 warning (0.00 sec) Rows matched: 0 Changed: 0 Warnings: 1 mysql> |
5.7&以及之后版本修改root密码,如下:
mysql> update mysql.user set authentication_string=password('root') where user = 'root'; Query OK, 0 rows affected, 1 warning (0.00 sec) Rows matched: 0 Changed: 0 Warnings: 1 mysql> |
4.5 重启mysql服务
重启mysql服务,如下:
[mysql5.7@tidb03 ~]$ kill -9 104823 104901 [mysql5.7@tidb03 ~]$ service mysql start Starting MySQL[ OK ] [1]+ Killed mysql/bin/mysqld_safe --skip-grant-tables [mysql5.7@tidb03 ~]$ ps -ef|grep mysql root 103595 86871 0 01:12 pts/0 00:00:00 su - mysql5.7 mysql5.7 103596 103595 0 01:12 pts/0 00:00:00 -bash mysql5.7 105360 1 0 01:35 pts/0 00:00:00 /bin/sh /home/mysql5.7/mysql/bin/mysqld_safe --datadir=/home/mysql5.7/mysql/data --pid-file=/home/mysql5.7/mysql/data/tidb03.dev.com.pid mysql5.7 105455 105360 0 01:35 pts/0 00:00:02 /home/mysql5.7/mysql/bin/mysqld --basedir=/home/mysql5.7/mysql --datadir=/home/mysql5.7/mysql/data --plugin-dir=/home/mysql5.7/mysql/lib/plugin --log-error=tidb03.dev.com.err --pid-file=/home/mysql5.7/mysql/data/tidb03.dev.com.pid mysql5.7 107911 103596 0 02:16 pts/0 00:00:00 ps -ef mysql5.7 107912 103596 0 02:16 pts/0 00:00:00 grep --color=auto mysql [mysql5.7@tidb03 ~]$ |
5. 编译安装mysql8.0
5.1 安装编译mysql需要的相关包
安装编译mysql需要的相关包,如下:
yum -y installncurses ncurses-devel openssl-devel bison gccgcc-c++ makecmake [root@tidb04 ~]# which cmake /usr/bin/cmake [root@tidb04 ~]# |
5.2 下载mysql8.0源码包
下载mysql地址:MySQL :: Download MySQL Community Server
5.3 上载mysql8.0源码包并解压
上载mysql8.0源码包并解压,如下:
[root@tidb04 ~]# cd /home/mysql8.0/ [root@tidb04 mysql8.0]# ls mysql-boost-8.0.26.tar.gz [root@tidb04 mysql8.0]# pwd /home/mysql8.0 [root@tidb04 mysql8.0]# tar -zxvf mysql-boost-8.0.26.tar.gz |
5.4 新建相关安装目录
新建相关安装目录,如下:
[root@tidb04 mysql8.0]# mkdir -p mysql/{data,etc} [root@tidb04 mysql8.0]# pwd /home/mysql8.0 [root@tidb04 mysql8.0]# ls mysql mysql-8.0.26 mysql-boost-8.0.26.tar.gz [root@tidb04 mysql8.0]# |
5.5 编译安装cmake
5.5.1 解压cmake
解压cmake,如下:
[root@tidb04 mysql8.0]# tar -zxvf cmake-3.21.0-linux-x86_64.tar.gz |
5.5.2 设置cmake
编译安装cmake,如下:
[root@tidb04 mysql8.0]# cp -r cmake-3.21.0-linux-x86_64 /usr/local/cmake [root@tidb04 mysql8.0]# /etc/profile 加入环境变量 export PATH=/usr/local/cmake/bin/:$PATH [root@tidb04 mysql8.0]# vi /etc/profile [root@tidb04 mysql8.0]# source /etc/profile [root@tidb04 mysql8.0]# which cmake /usr/local/cmake/bin/cmake [root@tidb04 mysql8.0]# |
5.5 编译安装mysql8.0
同理,编译安装mysql5.6,如下:
cmake \ -DCMAKE_INSTALL_PREFIX=/home/mysql8.0/mysql \ -DMYSQL_UNIX_ADDR=/home/mysql8.0/mysql/mysql.sock \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DMYSQL_DATADIR=/home/mysql8.0/mysql/data \ -DSYSCONFDIR=/home/mysql8.0/mysql/etc/my.cnf \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DENABLE_DEBUG_SYNC=0 \ -DENABLED_LOCAL_INFILE=1 \ -DFORCE_INSOURCE_BUILD=1 \ -DENABLED_PROFILING=1 \ -DMYSQL_TCP_PORT=3306 \ -DWITH_DEBUG=0 \ -DWITH_SSL=yes \ -DDOWNLOAD_BOOST=1 \ -DCMAKE_C_COMPILER=/usr/bin/gcc \ -DCMAKE_CXX_COMPILER=/usr/bin/g++ \ -DWITH_BOOST=boost |
报错,如下:
-- This is .el7. as found from 'rpm -qf /' -- Looking for a devtoolset compiler CMake Warning at CMakeLists.txt:313 (MESSAGE): Could not find devtoolset compiler in /opt/rh/devtoolset-10 CMake Error at CMakeLists.txt:315 (MESSAGE): Please set CMAKE_C_COMPILER and CMAKE_CXX_COMPILER explicitly. -- Configuring incomplete, errors occurred! [root@tidb04 mysql-8.0.26]# |
必须指定gcc编译器:
-DCMAKE_C_COMPILER=/usr/bin/gcc \ -DCMAKE_CXX_COMPILER=/usr/bin/g++ \ |
仍然报错,如下:
-- CMAKE_GENERATOR: Unix Makefiles CMake Error at cmake/os/Linux.cmake:75 (MESSAGE): GCC 5.3 or newer is required (-dumpversion says 4.8.5) Call Stack (most recent call first): CMakeLists.txt:564 (INCLUDE) |
5.6 升级gcc版本
下载gcc-9.3.0.tar.xz 并解压,升级gcc版本,如下:
http://www.netgull.com/gcc/releases/gcc-9.3.0/gcc-9.3.0.tar.xz |
下载:gmp-6.1.0.tar.bz2 isl-0.18.tar.bz2 mpc-1.0.3.tar.gz mpfr-3.1.4.tar.bz2
解压gcc,如下:
tar -xf gcc-9.3.0.tar.xz |
把压缩文件拷贝到当前目录。
5.7执行数据库初始化
执行授权,如下:
[root@tidb04 mysql8.0]# chown -R mysql8.0:mysql8.0 mysql [root@tidb04 mysql8.0]# su - mysql8.0 |
执行数据库初始化,如下:
[mysql8.0@tidb04 mysql]$ ./bin/mysqld --initialize-insecure --user=mysql8.0 --basedir=/home/mysql8.0/mysql --datadir=/home/mysql8.0/mysql/data 2021-08-23T23:30:25.525779Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release. 2021-08-23T23:30:25.525930Z 0 [System] [MY-013169] [Server] /home/mysql8.0/mysql/bin/mysqld (mysqld 8.0.26) initializing of server in progress as process 31455 2021-08-23T23:30:25.546837Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2021-08-23T23:30:26.339045Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 2021-08-23T23:30:27.412778Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main 2021-08-23T23:30:27.413359Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main 2021-08-23T23:30:27.509799Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option. [mysql8.0@tidb04 mysql]$ ls |
5.8设置mysql开机启动
执行如下:
[root@tidb04 mysql]## cd /home/mysql8.0/mysql [root@tidb04 mysql]# pwd /home/mysql8.0/mysql [root@tidb04 mysql]# ls bin data docs include lib LICENSE man mysql-test README README-test share support-files [root@tidb04 mysql]# cp support-files/mysql.server /etc/init.d/mysql [root@tidb04 mysql]# chmod 755 /etc/init.d/mysql [root@tidb04 mysql]# chown -R mysql8.0:mysql0.0 /etc/init.d/mysql [root@tidb04 mysql]# chkconfig mysql on [root@tidb04 mysql]# |
5.9设置mysql环境变量
设置mysql环境变量,执行如下:
[mysql8.0@tidb04 ~]$ vi .bash_profile [mysql8.0@tidb04 ~]$ source .bash_profile [mysql8.0@tidb04 ~]$ cat .bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/.local/bin:$HOME/bin export PATH export MYSQL_HOME=/home/mysql8.0/mysql export PATH=$MYSQL_HOME/bin:$PATH [mysql8.0@tidb04 ~]$ |
5.10配置文件.my.cnf
重命名默认配置文件,如下:
6. 导出mysql参数
6.1 生成excel报错
5.6生成excel报错,如下:
mysql> use information_schema Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> select * into outfile '/home/mysql5.6/mysql5.6_param.xls' from SESSION_VARIABLES; ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement mysql> set global secure_file_priv=''; ERROR 1238 (HY000): Variable 'secure_file_priv' is a read only variable mysql> exit |
参数说明:
查看 secure_file_priv 的值,默认为NULL,表示限制不能导入导出。 查看官方文档,secure_file_priv参数用于限制LOAD DATA, SELECT …OUTFILE, LOAD_FILE()传到哪个指定目录。 secure_file_priv 为NULL 时,表示限制mysqld不允许导入或导出。 secure_file_priv 为/tmp 时,表示限制mysqld只能在/tmp目录中执行导入导出,其他目录不能执行。 secure_file_priv 没有值时,表示不限制mysqld在任意目录的导入导出。 |
5.7.生成excel,报错,如下:
mysql> select * from SESSION_VARIABLES; ERROR 3167 (HY000): The 'INFORMATION_SCHEMA.SESSION_VARIABLES' feature is disabled; see the documentation for 'show_compatibility_56' mysql> show variables like 'show_compatibility_56'; +-----------------------+-------+ | Variable_name | Value | +-----------------------+-------+ | show_compatibility_56 | OFF | +-----------------------+-------+ 1 row in set (0.00 sec) mysql> |
6.2 查看mysql使用的配置文件
查看mysql5.5,如下:
[mysql5.5@tidb01 ~]$ mysql --help|grep 'my.cnf' order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/my.cnf /etc/mysql/my.cnf /home/mysql5.5/mysql/etc/my.cnf /home/mysql5.5/mysql/my.cnf ~/.my.cnf [mysql5.5@tidb01 ~]$ secure-file-priv='' [mysql5.5@tidb01 ~]$ |
查看mysql5.6,如下:
[mysql5.6@tidb02 ~]$ mysql --help|grep 'my.cnf' order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/my.cnf /etc/mysql/my.cnf /home/mysql5.7/mysql/etc/my.cnf /home/mysql5.6/mysql/my.cnf ~/.my.cnf [mysql5.6@tidb02 ~]$ |
查看mysql5.7,如下:
[mysql5.7@tidb03 ~]$ mysql --help|grep 'my.cnf' order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/my.cnf /etc/mysql/my.cnf /home/mysql5.7/mysql/my.cnf/my.cnf /home/mysql5.7/mysql/my.cnf ~/.my.cnf [mysql5.7@tidb03 ~]$ |