博主今天分享在centos6.9的minimal版本上安裝mysql5.6.40的全過程,此過程至關繁瑣,請你們耐心一步步安裝。mysql
安裝步驟:linux
(1)下載mysql版本mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz,地址:https://dev.mysql.com/downloads/mysql/web
(2)上傳mysql壓縮包sql
(3)解壓mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz到/usr/local目錄bootstrap
(4)重命名解壓包centos
(5)建立mysql用戶,而且設置密碼(123456)bash
(6)將mysql目錄的權限授給mysql用戶和mysql組服務器
(7)切換到mysql用戶,執行安裝less
(8)因爲上一步安裝時報錯「-bash: /usr/local/mysql/scripts/mysql_install_db: /usr/bin/perl: bad interpreter: 沒有那個文件或目錄」,須要切換到root用戶,安裝perl以及perl-devel,執行命令:yum -y install perl perl-develui
(9)繼續安裝mysql命令,並報錯「Installing MySQL system tables.../usr/local/mysql/bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory」
(10)因爲上一步報錯缺乏libaio相關包,此處須要安裝libaio相關包
(11)繼續執行安裝mysql命令,報錯缺乏libnuma.so.1相關包
(12)因爲上一步驟報錯缺乏「libnuma.so.1」,經分析時缺乏numactl相關包,此處須要安裝numactl相關包
(13)繼續執行安裝mysql命令,安裝成功
(14)斷開secureCRT鏈接,拷貝出安裝mysql命令後的提示(此步驟很重要,內含有mysql重要信息)
[root@centos-aaron-03 ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data Installing MySQL system tables...2018-07-09 07:09:32 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2018-07-09 07:09:32 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap. 2018-07-09 07:09:32 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.40) starting as process 1792 ... 2018-07-09 07:09:32 1792 [Note] InnoDB: Using atomics to ref count buffer pool pages 2018-07-09 07:09:32 1792 [Note] InnoDB: The InnoDB memory heap is disabled 2018-07-09 07:09:32 1792 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2018-07-09 07:09:32 1792 [Note] InnoDB: Memory barrier is not used 2018-07-09 07:09:32 1792 [Note] InnoDB: Compressed tables use zlib 1.2.3 2018-07-09 07:09:32 1792 [Note] InnoDB: Using Linux native AIO 2018-07-09 07:09:32 1792 [Note] InnoDB: Using CPU crc32 instructions 2018-07-09 07:09:32 1792 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2018-07-09 07:09:32 1792 [Note] InnoDB: Completed initialization of buffer pool 2018-07-09 07:09:32 1792 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created! 2018-07-09 07:09:32 1792 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB 2018-07-09 07:09:32 1792 [Note] InnoDB: Database physically writes the file full: wait... 2018-07-09 07:09:32 1792 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB 2018-07-09 07:09:32 1792 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB 2018-07-09 07:09:32 1792 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0 2018-07-09 07:09:32 1792 [Warning] InnoDB: New log files created, LSN=45781 2018-07-09 07:09:32 1792 [Note] InnoDB: Doublewrite buffer not found: creating new 2018-07-09 07:09:32 1792 [Note] InnoDB: Doublewrite buffer created 2018-07-09 07:09:32 1792 [Note] InnoDB: 128 rollback segment(s) are active. 2018-07-09 07:09:32 1792 [Warning] InnoDB: Creating foreign key constraint system tables. 2018-07-09 07:09:32 1792 [Note] InnoDB: Foreign key constraint system tables created 2018-07-09 07:09:32 1792 [Note] InnoDB: Creating tablespace and datafile system tables. 2018-07-09 07:09:32 1792 [Note] InnoDB: Tablespace and datafile system tables created. 2018-07-09 07:09:32 1792 [Note] InnoDB: Waiting for purge to start 2018-07-09 07:09:32 1792 [Note] InnoDB: 5.6.40 started; log sequence number 0 2018-07-09 07:09:32 1792 [Note] Binlog end 2018-07-09 07:09:32 1792 [Note] InnoDB: FTS optimize thread exiting. 2018-07-09 07:09:32 1792 [Note] InnoDB: Starting shutdown... 2018-07-09 07:09:34 1792 [Note] InnoDB: Shutdown completed; log sequence number 1625977 OK Filling help tables...2018-07-09 07:09:34 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2018-07-09 07:09:34 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap. 2018-07-09 07:09:34 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.40) starting as process 1814 ... 2018-07-09 07:09:34 1814 [Note] InnoDB: Using atomics to ref count buffer pool pages 2018-07-09 07:09:34 1814 [Note] InnoDB: The InnoDB memory heap is disabled 2018-07-09 07:09:34 1814 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2018-07-09 07:09:34 1814 [Note] InnoDB: Memory barrier is not used 2018-07-09 07:09:34 1814 [Note] InnoDB: Compressed tables use zlib 1.2.3 2018-07-09 07:09:34 1814 [Note] InnoDB: Using Linux native AIO 2018-07-09 07:09:34 1814 [Note] InnoDB: Using CPU crc32 instructions 2018-07-09 07:09:34 1814 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2018-07-09 07:09:34 1814 [Note] InnoDB: Completed initialization of buffer pool 2018-07-09 07:09:34 1814 [Note] InnoDB: Highest supported file format is Barracuda. 2018-07-09 07:09:34 1814 [Note] InnoDB: 128 rollback segment(s) are active. 2018-07-09 07:09:34 1814 [Note] InnoDB: Waiting for purge to start 2018-07-09 07:09:34 1814 [Note] InnoDB: 5.6.40 started; log sequence number 1625977 2018-07-09 07:09:34 1814 [Note] Binlog end 2018-07-09 07:09:34 1814 [Note] InnoDB: FTS optimize thread exiting. 2018-07-09 07:09:34 1814 [Note] InnoDB: Starting shutdown... 2018-07-09 07:09:36 1814 [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: /usr/local/mysql/bin/mysqladmin -u root password 'new-password' /usr/local/mysql/bin/mysqladmin -u root -h centos-aaron-03 password 'new-password' Alternatively you can run: /usr/local/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 . ; /usr/local/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 WARNING: Found existing config file /usr/local/mysql/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 /usr/local/mysql/my-new.cnf, please compare it with your file and take the changes you need. WARNING: Default config file /etc/my.cnf exists on the system This file will be read by default by the MySQL server If you do not want to use this, either remove it, or use the --defaults-file argument to mysqld_safe when starting the server
(15)切換到root用戶,複製並修改配置文件,添加msql服務
(16)修改配置文件
(17)配置mysql的環境變量,而且從新加載配置文件
vi /etc/profile source /etc/profile
(18)切換到mysql用戶,啓用mysql,配置mysql開機自動啓動
(19)設置mysql的root用戶密碼123456
(20)用root用戶登陸mysql
(注意:當執行quit退出再從新登陸,可能報ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)異常,解決方法以下:
方法一: (1)關閉mysql [mysql@localhost ~]$ service mysql stop (2)屏蔽權限 [mysql@localhost ~]$ mysqld_safe --skip-grant-table 屏幕出現: Starting demo from ….. (3)新開起一個終端輸入 [mysql@localhost ~]$ mysql -u root mysql mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root'; mysql> FLUSH PRIVILEGES;//記得要這句話,不然若是關閉先前的終端,又會出現原來的錯誤 mysql>quit 方法二: (1)關閉mysql [mysql@localhost ~]$ service mysql stop (2)屏蔽權限 [mysql@localhost ~]$ mysqld_safe --skip-grant-table 屏幕出現: Starting demo from ….. (3)新開起一個終端輸入 [mysql@localhost ~]$ mysql -u root mysql mysql> delete from user where USER=''; mysql> FLUSH PRIVILEGES;//記得要這句話,不然若是關閉先前的終端,又會出現原來的錯誤 mysql>quit
(21)讓遠程客戶端能夠鏈接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> SELECT `Host`,`User` FROM user; 更新用戶表 : mysql> UPDATE user SET `Host` = '%' WHERE `User` = 'root' LIMIT 1; 注:host=localhost 那此用戶就不具備遠程訪問權限,修改成%的意思是容許全部的ip遠程訪問,若是須要指定具體的某個ip就寫上具體的ip便可 強制刷新權限 : mysql> flush privileges; 或者經過受權的方式: mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; 若是須要指定具體的某個ip就把%替換成具體的ip: mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.194.20' IDENTIFIED BY '123456' WITH GRANT OPTION; 別忘記強制刷新權限 : mysql> flush privileges; 查看端口sql: mysql> show global variables like 'port';
最後總結:centos最小化安裝的版本安裝mysql步驟真夠多的,缺包太多;建議不熟悉的小白們仍是使用其餘版本的centos安裝。