以下为在centos6上用普通安装mysql5.6过程的记录。开始踩过不少坑,特整理记录下过程,把安装尽可能简单化。5.6系列与5.7系列使用普通用户安装存在些许差异,后续会说到,希望能帮助到读者。
软件下载参考前文:https://blog.csdn.net/ohaozy/article/details/103435471
[root@localhost ~]# useradd mysql
[root@localhost ~]# passwd mysql
[root@localhost ~]# mkdir /data
[root@localhost ~]# chown mysql:mysql /data
[root@localhost ~]# su - mysql
Last login: Fri Nov 29 22:05:22 PST 2019 on pts/0
[mysql@localhost ~]$ mkdir /data/soft
#上传软件包到/data/soft
[mysql@localhost ~]$ cd /data/soft/
[mysql@localhost soft]$ ls
MySQL-5.6.36-1.el7.x86_64.rpm-bundle.tar MySQL-devel-5.6.36-1.el7.x86_64.rpm MySQL-server-5.6.36-1.el7.x86_64.rpm MySQL-shared-compat-5.6.36-1.el7.x86_64.rpm
MySQL-client-5.6.36-1.el7.x86_64.rpm MySQL-embedded-5.6.36-1.el7.x86_64.rpm MySQL-shared-5.6.36-1.el7.x86_64.rpm MySQL-test-5.6.36-1.el7.x86_64.rpm
#5.6系列解压server包和client即可
[mysql@localhost soft]$ rpm2cpio MySQL-server-5.6.36-1.el7.x86_64.rpm | cpio -idvm
./var/lib/mysql-files
。。。。。。。。。
517986 blocks
[mysql@localhost soft]$ rpm2cpio MySQL-client-5.6.36-1.el7.x86_64.rpm | cpio -idvm
./usr/bin/msql2mysql
./usr/share/man/man1/mysqlslap.1.gz
。。。。。。。
180598 blocks
[mysql@localhost soft]$ rpm -qa|grep libai
libaio-0.3.109-13.el7.x86_64
[root@localhost ~]# rpm -qa|grep numactl
numactl-libs-2.0.9-2.el7.x86_64
如果没有上面两个,则需要root用户安装:yum install -y libaio numactl
[mysql@localhost soft]$ mkdir /data/mysql
[mysql@localhost soft]$ mv etc/ /data/mysql/
[mysql@localhost soft]$ mv usr/ /data/mysql/
[mysql@localhost soft]$ mv var/ /data/mysql/
[mysql@localhost mysql]$ mkdir /data
[mysql@localhost mysql]$ mkdir /data/mysql/data/tmp
[mysql@localhost mysql]$ cd /data/mysql
[mysql@localhost mysql]$ ls etc
init.d logrotate.d my.cnf.d
[mysql@localhost mysql]$ vi etc/my.cnf
[mysqld]
federated
symbolic-links=0
port=3306
socket=/data/mysql/var/lib/mysql/mysql.sock
basedir=/data/mysql/usr
datadir=/data/mysql/data
tmpdir=/data/mysql/data/tmp
secure-file-priv=/data/mysql/var/lib/mysql-files
collation_server=utf8_unicode_ci
character_set_server=utf8
[mysql@localhost mysql]$ vi ~/.bash_profile
PATH=$PATH:$HOME/.local/bin:$HOME/bin:/data/mysql/usr/bin:/data/mysql/usr/sbin
[mysql@localhost mysql]$ source ~/.bash_profile
[root@localhost ~]# yum -y install autoconf #需要root安装autoconf,否则mysql用户执行:mysql_install_db报错
。。。。。。。。。。。。。
Installed:
autoconf.noarch 0:2.69-11.el7
Dependency Installed:
m4.x86_64 0:1.4.16-10.el7 perl-Data-Dumper.x86_64 0:2.145-3.el7
Complete!
[mysql@localhost mysql]$ mysql_install_db --user=mysql --basedir=/data/mysql/usr --defaults-file=/data/mysql/etc/my.cnf
Installing MySQL system tables...2019-11-29 22:16:43 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-11-29 22:16:43 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2019-11-29 22:16:43 0 [Note] /data/mysql/usr/sbin/mysqld (mysqld 5.6.36) starting as process 2498 ...
2019-11-29 22:16:43 2498 [Warning] Buffered warning: Changed limits: max_open_files: 1024 (requested 5000)
2019-11-29 22:16:43 2498 [Warning] Buffered warning: Changed limits: table_open_cache: 431 (requested 2000)
2019-11-29 22:16:43 2498 [Note] InnoDB: Using atomics to ref count buffer pool pages
2019-11-29 22:16:43 2498 [Note] InnoDB: The InnoDB memory heap is disabled
2019-11-29 22:16:43 2498 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-11-29 22:16:43 2498 [Note] InnoDB: Memory barrier is not used
2019-11-29 22:16:43 2498 [Note] InnoDB: Compressed tables use zlib 1.2.3
2019-11-29 22:16:43 2498 [Note] InnoDB: Using Linux native AIO
2019-11-29 22:16:43 2498 [Note] InnoDB: Using CPU crc32 instructions
2019-11-29 22:16:43 2498 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2019-11-29 22:16:43 2498 [Note] InnoDB: Completed initialization of buffer pool
2019-11-29 22:16:43 2498 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2019-11-29 22:16:43 2498 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2019-11-29 22:16:43 2498 [Note] InnoDB: Database physically writes the file full: wait...
2019-11-29 22:16:43 2498 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2019-11-29 22:16:43 2498 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2019-11-29 22:16:44 2498 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2019-11-29 22:16:44 2498 [Warning] InnoDB: New log files created, LSN=45781
2019-11-29 22:16:44 2498 [Note] InnoDB: Doublewrite buffer not found: creating new
2019-11-29 22:16:44 2498 [Note] InnoDB: Doublewrite buffer created
2019-11-29 22:16:44 2498 [Note] InnoDB: 128 rollback segment(s) are active.
2019-11-29 22:16:44 2498 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-11-29 22:16:44 2498 [Note] InnoDB: Foreign key constraint system tables created
2019-11-29 22:16:44 2498 [Note] InnoDB: Creating tablespace and datafile system tables.
2019-11-29 22:16:44 2498 [Note] InnoDB: Tablespace and datafile system tables created.
2019-11-29 22:16:44 2498 [Note] InnoDB: Waiting for purge to start
2019-11-29 22:16:44 2498 [Note] InnoDB: 5.6.36 started; log sequence number 0
2019-11-29 22:16:44 2498 [Note] Binlog end
2019-11-29 22:16:44 2498 [Note] InnoDB: FTS optimize thread exiting.
2019-11-29 22:16:44 2498 [Note] InnoDB: Starting shutdown...
2019-11-29 22:16:46 2498 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK
Filling help tables...2019-11-29 22:16:46 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-11-29 22:16:46 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2019-11-29 22:16:46 0 [Note] /data/mysql/usr/sbin/mysqld (mysqld 5.6.36) starting as process 2520 ...
2019-11-29 22:16:46 2520 [Warning] Buffered warning: Changed limits: max_open_files: 1024 (requested 5000)
2019-11-29 22:16:46 2520 [Warning] Buffered warning: Changed limits: table_open_cache: 431 (requested 2000)
2019-11-29 22:16:46 2520 [Note] InnoDB: Using atomics to ref count buffer pool pages
2019-11-29 22:16:46 2520 [Note] InnoDB: The InnoDB memory heap is disabled
2019-11-29 22:16:46 2520 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-11-29 22:16:46 2520 [Note] InnoDB: Memory barrier is not used
2019-11-29 22:16:46 2520 [Note] InnoDB: Compressed tables use zlib 1.2.3
2019-11-29 22:16:46 2520 [Note] InnoDB: Using Linux native AIO
2019-11-29 22:16:46 2520 [Note] InnoDB: Using CPU crc32 instructions
2019-11-29 22:16:46 2520 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2019-11-29 22:16:46 2520 [Note] InnoDB: Completed initialization of buffer pool
2019-11-29 22:16:46 2520 [Note] InnoDB: Highest supported file format is Barracuda.
2019-11-29 22:16:46 2520 [Note] InnoDB: 128 rollback segment(s) are active.
2019-11-29 22:16:46 2520 [Note] InnoDB: Waiting for purge to start
2019-11-29 22:16:46 2520 [Note] InnoDB: 5.6.36 started; log sequence number 1625977
2019-11-29 22:16:46 2520 [Note] Binlog end
2019-11-29 22:16:46 2520 [Note] InnoDB: FTS optimize thread exiting.
2019-11-29 22:16:46 2520 [Note] InnoDB: Starting shutdown...
2019-11-29 22:16:48 2520 [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:
/data/mysql/usr/bin/mysqladmin -u root password 'new-password' #提示你修改密码的命令
/data/mysql/usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
Alternatively you can run:
/data/mysql/usr/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 /usr ; /data/mysql/usr/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
WARNING: Found existing config file /data/mysql/usr/my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as /data/mysql/usr/my-new.cnf,
please compare it with your file and take the changes you need.
[mysql@localhost mysql]$ mysqld --defaults-file=/data/mysql/etc/my.cnf --user=mysql & #启动
[1] 2545
[mysql@localhost mysql]$ 2019-11-29 22:19:48 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-11-29 22:19:48 0 [Note] mysqld (mysqld 5.6.36) starting as process 2545 ...
2019-11-29 22:19:48 2545 [Warning] Buffered warning: Changed limits: max_open_files: 1024 (requested 5000)
2019-11-29 22:19:48 2545 [Warning] Buffered warning: Changed limits: table_open_cache: 431 (requested 2000)
2019-11-29 22:19:48 2545 [Note] InnoDB: Using atomics to ref count buffer pool pages
2019-11-29 22:19:48 2545 [Note] InnoDB: The InnoDB memory heap is disabled
2019-11-29 22:19:48 2545 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-11-29 22:19:48 2545 [Note] InnoDB: Memory barrier is not used
2019-11-29 22:19:48 2545 [Note] InnoDB: Compressed tables use zlib 1.2.3
2019-11-29 22:19:48 2545 [Note] InnoDB: Using Linux native AIO
2019-11-29 22:19:48 2545 [Note] InnoDB: Using CPU crc32 instructions
2019-11-29 22:19:48 2545 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2019-11-29 22:19:48 2545 [Note] InnoDB: Completed initialization of buffer pool
2019-11-29 22:19:48 2545 [Note] InnoDB: Highest supported file format is Barracuda.
2019-11-29 22:19:48 2545 [Note] InnoDB: 128 rollback segment(s) are active.
2019-11-29 22:19:48 2545 [Note] InnoDB: Waiting for purge to start
2019-11-29 22:19:48 2545 [Note] InnoDB: 5.6.36 started; log sequence number 1625987
2019-11-29 22:19:48 2545 [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: 6923a85a-1339-11ea-a58c-000c2953de29.
2019-11-29 22:19:48 2545 [Note] Server hostname (bind-address): '*'; port: 3306
2019-11-29 22:19:48 2545 [Note] IPv6 is available.
2019-11-29 22:19:48 2545 [Note] - '::' resolves to '::';
2019-11-29 22:19:48 2545 [Note] Server socket created on IP: '::'.
2019-11-29 22:19:48 2545 [Note] Event Scheduler: Loaded 0 events
2019-11-29 22:19:48 2545 [Note] mysqld: ready for connections.
Version: '5.6.36' socket: '/data/mysql/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server (GPL)
[mysql@localhost mysql]$ ln -s /data/mysql/var/lib/mysql/mysql.sock /tmp/mysql.sock
[mysql@localhost mysql]$ mysql -uroot -proot -S /tmp/mysql.sock
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.36 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> show schemas;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| tmp |
+--------------------+
5 rows in set (0.00 sec)
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> select host,user from user;
+-----------------------+------+
| host | user |
+-----------------------+------+
| 127.0.0.1 | root |
| ::1 | root |
| localhost | |
| localhost | root |
| localhost.localdomain | |
| localhost.localdomain | root |
+-----------------------+------+
6 rows in set (0.00 sec)
mysql> exit
[mysql@localhost mysql]$ mysqladmin -uroot -proot shutdown -S /tmp/mysql.sock
Warning: Using a password on the command line interface can be insecure.
2019-11-29 22:38:39 2545 [Note] mysqld: Normal shutdown
2019-11-29 22:38:39 2545 [Note] Giving 0 client threads a chance to die gracefully
2019-11-29 22:38:39 2545 [Note] Event Scheduler: Purging the queue. 0 events
2019-11-29 22:38:39 2545 [Note] Shutting down slave threads
2019-11-29 22:38:39 2545 [Note] Forcefully disconnecting 0 remaining clients
2019-11-29 22:38:39 2545 [Note] Binlog end
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'partition'
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'INNODB_FT_DELETED'
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'INNODB_METRICS'
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'INNODB_CMPMEM'
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'INNODB_CMP_RESET'
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'INNODB_CMP'
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'INNODB_LOCKS'
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'INNODB_TRX'
2019-11-29 22:38:39 2545 [Note] Shutting down plugin 'InnoDB'
2019-11-29 22:38:39 2545 [Note] InnoDB: FTS optimize thread exiting.
2019-11-29 22:38:39 2545 [Note] InnoDB: Starting shutdown...
2019-11-29 22:38:40 2545 [Note] InnoDB: Shutdown completed; log sequence number 1625997
2019-11-29 22:38:40 2545 [Note] Shutting down plugin 'FEDERATED'
2019-11-29 22:38:40 2545 [Note] Shutting down plugin 'BLACKHOLE'
2019-11-29 22:38:40 2545 [Note] Shutting down plugin 'ARCHIVE'
2019-11-29 22:38:40 2545 [Note] Shutting down plugin 'MRG_MYISAM'
2019-11-29 22:38:40 2545 [Note] Shutting down plugin 'MyISAM'
2019-11-29 22:38:40 2545 [Note] Shutting down plugin 'MEMORY'
2019-11-29 22:38:40 2545 [Note] Shutting down plugin 'CSV'
2019-11-29 22:38:40 2545 [Note] Shutting down plugin 'sha256_password'
2019-11-29 22:38:40 2545 [Note] Shutting down plugin 'mysql_old_password'
2019-11-29 22:38:40 2545 [Note] Shutting down plugin 'mysql_native_password'
2019-11-29 22:38:40 2545 [Note] Shutting down plugin 'binlog'
2019-11-29 22:38:40 2545 [Note] mysqld: Shutdown complete
[1]+ Done mysqld --defaults-file=/data/mysql/etc/my.cnf --user=mysql
[mysql@localhost mysql]$
到此,普通用户安装结束。
附:
使用mysqld_safe启动:
mysqld_safe --basedir=/data/mysql/usr --datadir=/data/mysql/data --user=mysql --log-error=/data/mysql/mysql.err --pid-file=/data/mysql/data/mysql.pid --socket=/data/mysql/var/lib/mysql/mysql.sock --secure-file-priv=/data/mysql/var/lib/mysql-files --port=3306 &
#chkconfig命令设置自启动mysql服务,视情况修改:/etc/rc.d/init.d/mysqld
[root@linuxidc support-files]# cp ./mysql.server /etc/rc.d/init.d/mysqld
[root@linuxidc support-files]# chkconfig --add mysqld
[root@linuxidc support-files]# chkconfig mysqld on