下載地址
- 地址 (提取碼: mubi)
- 名稱:
MySQL-5.6.22-1.el6.i686.rpm-bundle.tar
前置條件
新建虛擬機(jī)時(shí)最好給4G~8G的內(nèi)存惦积,不然最后啟動(dòng)mysql時(shí)會(huì)因?yàn)閮?nèi)存不夠而報(bào)錯(cuò)
安裝步驟
1. 使用sftp工具 快捷鍵: alt + p
上傳 MySQL-5.6.22-1.el6.i686.rpm-bundle.tar
文件到linux
sftp> put F:\software\MySQL-5.6.22-1.el6.i686.rpm-bundle.tar
默認(rèn)上傳的位置
[root@localhost ~]# ls
anaconda-ks.cfg MySQL-5.6.22-1.el6.i686.rpm-bundle.tar
移動(dòng)到/usr/local/mysql
下
[root@localhost ~]# mv MySQL-5.6.22-1.el6.i686.rpm-bundle.tar /usr/local/mysql
2. 查看是否已經(jīng)安裝mysql
rpm -qa | grep -i mysql
3. 解壓tar文件
進(jìn)入cd /usr/local/mysql
目錄
[root@localhost ~]# cd /usr/local/mysql
[root@localhost mysql]# ls
MySQL-5.6.22-1.el6.i686.rpm-bundle.tar
- 命令
tar -xvf MySQL-5.6.22-1.el6.i686.rpm-bundle.tar
- 執(zhí)行結(jié)果
[root@localhost mysql]# tar -xvf MySQL-5.6.22-1.el6.i686.rpm-bundle.tar
MySQL-shared-compat-5.6.22-1.el6.i686.rpm
MySQL-server-5.6.22-1.el6.i686.rpm
MySQL-client-5.6.22-1.el6.i686.rpm
MySQL-devel-5.6.22-1.el6.i686.rpm
MySQL-test-5.6.22-1.el6.i686.rpm
MySQL-shared-5.6.22-1.el6.i686.rpm
MySQL-embedded-5.6.22-1.el6.i686.rpm
注意:在新版本的CentOS7中,默認(rèn)的數(shù)據(jù)庫已更新為了Mariadb,而非 MySQL,所以執(zhí)行
yum install mysql
命令只是更新Mariadb數(shù)據(jù)庫,并不會(huì)安裝 MySQL 树绩。
4. 解決沖突的rpm組件
(1). postfix
查看postfix
rpm -qa | grep -i postfix
卸載postfix
rpm -ev postfix-2.10.1-7.el7.x86_64
(2). mariadb
查看已安裝的 Mariadb 數(shù)據(jù)庫
rpm -qa | grep -i mariadb
卸載已安裝的 Mariadb 數(shù)據(jù)庫
rpm -ev mariadb-libs-5.5.64-1.el7.x86_64
5. 安裝依賴組件
安裝服務(wù)端時(shí):rpm -ivh MySQL-server-5.6.22-1.el6.i686.rpm
出現(xiàn)了以下的問題
[root@localhost mysql]# rpm -ivh MySQL-server-5.6.22-1.el6.i686.rpm
error: Failed dependencies:
/usr/bin/perl is needed by MySQL-server-5.6.22-1.el6.i686
libaio.so.1 is needed by MySQL-server-5.6.22-1.el6.i686
libaio.so.1(LIBAIO_0.1) is needed by MySQL-server-5.6.22-1.el6.i686
libaio.so.1(LIBAIO_0.4) is needed by MySQL-server-5.6.22-1.el6.i686
libc.so.6 is needed by MySQL-server-5.6.22-1.el6.i686
libc.so.6(GLIBC_2.0) is needed by MySQL-server-5.6.22-1.el6.i686
libc.so.6(GLIBC_2.1) is needed by MySQL-server-5.6.22-1.el6.i686
libc.so.6(GLIBC_2.1.2) is needed by MySQL-server-5.6.22-1.el6.i686
libc.so.6(GLIBC_2.1.3) is needed by MySQL-server-5.6.22-1.el6.i686
libc.so.6(GLIBC_2.10) is needed by MySQL-server-5.6.22-1.el6.i686
libc.so.6(GLIBC_2.2) is needed by MySQL-server-5.6.22-1.el6.i686
libc.so.6(GLIBC_2.2.3) is needed by MySQL-server-5.6.22-1.el6.i686
libc.so.6(GLIBC_2.3) is needed by MySQL-server-5.6.22-1.el6.i686
libc.so.6(GLIBC_2.3.3) is needed by MySQL-server-5.6.22-1.el6.i686
libc.so.6(GLIBC_2.3.4) is needed by MySQL-server-5.6.22-1.el6.i686
libc.so.6(GLIBC_2.4) is needed by MySQL-server-5.6.22-1.el6.i686
libc.so.6(GLIBC_2.7) is needed by MySQL-server-5.6.22-1.el6.i686
libc.so.6(GLIBC_2.8) is needed by MySQL-server-5.6.22-1.el6.i686
libcrypt.so.1 is needed by MySQL-server-5.6.22-1.el6.i686
libcrypt.so.1(GLIBC_2.0) is needed by MySQL-server-5.6.22-1.el6.i686
libdl.so.2 is needed by MySQL-server-5.6.22-1.el6.i686
libdl.so.2(GLIBC_2.0) is needed by MySQL-server-5.6.22-1.el6.i686
libdl.so.2(GLIBC_2.1) is needed by MySQL-server-5.6.22-1.el6.i686
libgcc_s.so.1 is needed by MySQL-server-5.6.22-1.el6.i686
libgcc_s.so.1(GCC_3.0) is needed by MySQL-server-5.6.22-1.el6.i686
libgcc_s.so.1(GLIBC_2.0) is needed by MySQL-server-5.6.22-1.el6.i686
libm.so.6 is needed by MySQL-server-5.6.22-1.el6.i686
libm.so.6(GLIBC_2.0) is needed by MySQL-server-5.6.22-1.el6.i686
libm.so.6(GLIBC_2.1) is needed by MySQL-server-5.6.22-1.el6.i686
libpthread.so.0 is MySQL-server-5.6.22-1.el6.i686
libpthread.so.0(GLIBC_2.0) is needed by MySQL-server-5.6.22-1.el6.i686
libpthread.so.0(GLIBC_2.1) is needed by MySQL-server-5.6.22-1.el6.i686
libpthread.so.0(GLIBC_2.2) is needed by MySQL-server-5.6.22-1.el6.i686
libpthread.so.0(GLIBC_2.3.2) is needed by MySQL-server-5.6.22-1.el6.i686
librt.so.1 is needed by MySQL-server-5.6.22-1.el6.i686
librt.so.1(GLIBC_2.2) is needed by MySQL-server-5.6.22-1.el6.i686
libstdc++.so.6 is needed by MySQL-server-5.6.22-1.el6.i686
libstdc++.so.6(CXXABI_1.3) is needed by MySQL-server-5.6.22-1.el6.i686
libstdc++.so.6(GLIBCXX_3.4) is needed by MySQL-server-5.6.22-1.el6.i686
libstdc++.so.6(GLIBCXX_3.4.11) is needed by MySQL-server-5.6.22-1.el6.i686
libstdc++.so.6(GLIBCXX_3.4.9) is needed by MySQL-server-5.6.22-1.el6.i686
net-tools is needed by MySQL-server-5.6.22-1.el6.i686
由上面的錯(cuò)誤可以看出我們需要安裝相應(yīng)的依賴
perl
libaio.so.1
libc.so.6
libcrypt.so.1
libdl.so.2
libgcc_s.so.1
libm.so.6
libpthread.so.0
librt.so.1
libstdc++.so.6
net-tools
列出資源庫中特定的可以安裝或已經(jīng)安裝的rpm包的列表
libc.so.6柴钻,該庫對應(yīng)的軟件包名稱為glibc
yum list glibc*
已加載插件:fastestmirror
Determining fastest mirrors
* base: mirrors.aliyun.com
* extras: mirrors.163.com
* updates: mirrors.163.com
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/4): base/7/x86_64/group_gz | 165 kB 00:00:00
(2/4): extras/7/x86_64/primary_db | 165 kB 00:00:06
(3/4): base/7/x86_64/primary_db | 6.0 MB 00:00:15
(4/4): updates/7/x86_64/primary_db | 7.6 MB 00:00:19
已安裝的軟件包
glibc.x86_64 2.17-292.el7 @anaconda
glibc-common.x86_64 2.17-292.el7 @anaconda
可安裝的軟件包
glibc.i686 2.17-292.el7 base
glibc-devel.i686 2.17-292.el7 base
glibc-devel.x86_64 2.17-292.el7 base
glibc-headers.x86_64 2.17-292.el7 base
glibc-static.i686 2.17-292.el7 base
glibc-static.x86_64 2.17-292.el7 base
glibc-utils.x86_64 2.17-292.el7 base
安裝依賴
yum -y install glibc.i686
再次運(yùn)行rpm -ivh MySQL-server-5.6.22-1.el6.i686.rpm
查看缺少哪些依賴
[root@localhost mysql]# rpm -ivh MySQL-server-5.6.22-1.el6.i686.rpm
error: Failed dependencies:
/usr/bin/perl is needed by MySQL-server-5.6.22-1.el6.i686
libaio.so.1 is needed by MySQL-server-5.6.22-1.el6.i686
libaio.so.1(LIBAIO_0.1) is needed by MySQL-server-5.6.22-1.el6.i686
libaio.so.1(LIBAIO_0.4) is needed by MySQL-server-5.6.22-1.el6.i686
libgcc_s.so.1 is needed by MySQL-server-5.6.22-1.el6.i686
libgcc_s.so.1(GCC_3.0) is needed by MySQL-server-5.6.22-1.el6.i686
libgcc_s.so.1(GLIBC_2.0) is needed by MySQL-server-5.6.22-1.el6.i686
libstdc++.so.6 is needed by MySQL-server-5.6.22-1.el6.i686
libstdc++.so.6(CXXABI_1.3) is needed by MySQL-server-5.6.22-1.el6.i686
libstdc++.so.6(GLIBCXX_3.4) is needed by MySQL-server-5.6.22-1.el6.i686
libstdc++.so.6(GLIBCXX_3.4.11) is needed by MySQL-server-5.6.22-1.el6.i686
libstdc++.so.6(GLIBCXX_3.4.9) is needed by MySQL-server-5.6.22-1.el6.i686
net-tools is needed by MySQL-server-5.6.22-1.el6.i686
最后剩下5個(gè)
perl
libaio.so.1
libgcc_s.so.1
libstdc++.so.6
net-tools
依次安裝需要的依賴
yum -y install perl
yum -y install libaio.so.1
yum -y install libgcc_s.so.1
yum -y install libstdc++.so.6
yum -y install net-tools
需要安裝autoconf插件
yum -y install autoconf
最后安裝服務(wù)端:rpm -ivh MySQL-server-5.6.22-1.el6.i686.rpm
[root@localhost mysql]# rpm -ivh MySQL-server-5.6.22-1.el6.i686.rpm
準(zhǔn)備中... ################################# [100%]
正在升級/安裝...
1:MySQL-server-5.6.22-1.el6 ################################# [100%]
警告:用戶mysql 不存在 - 使用root
警告:群組mysql 不存在 - 使用root
2020-04-15 22:54:26 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-04-15 22:54:26 9778 [Note] InnoDB: Using atomics to ref count buffer pool pages
2020-04-15 22:54:26 9778 [Note] InnoDB: The InnoDB memory heap is disabled
2020-04-15 22:54:26 9778 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-04-15 22:54:26 9778 [Note] InnoDB: Memory barrier is not used
2020-04-15 22:54:26 9778 [Note] InnoDB: Compressed tables use zlib 1.2.3
2020-04-15 22:54:26 9778 [Note] InnoDB: Using Linux native AIO
2020-04-15 22:54:26 9778 [Note] InnoDB: Not using CPU crc32 instructions
2020-04-15 22:54:26 9778 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2020-04-15 22:54:26 9778 [Note] InnoDB: Completed initialization of buffer pool
2020-04-15 22:54:26 9778 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2020-04-15 22:54:26 9778 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2020-04-15 22:54:26 9778 [Note] InnoDB: Database physically writes the file full: wait...
2020-04-15 22:54:26 9778 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2020-04-15 22:54:26 9778 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2020-04-15 22:54:26 9778 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2020-04-15 22:54:26 9778 [Warning] InnoDB: New log files created, LSN=45781
2020-04-15 22:54:26 9778 [Note] InnoDB: Doublewrite buffer not found: creating new
2020-04-15 22:54:26 9778 [Note] InnoDB: Doublewrite buffer created
2020-04-15 22:54:26 9778 [Note] InnoDB: 128 rollback segment(s) are active.
2020-04-15 22:54:26 9778 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-04-15 22:54:26 9778 [Note] InnoDB: Foreign key constraint system tables created
2020-04-15 22:54:26 9778 [Note] InnoDB: Creating tablespace and datafile system tables.
2020-04-15 22:54:26 9778 [Note] InnoDB: Tablespace and datafile system tables created.
2020-04-15 22:54:26 9778 [Note] InnoDB: Waiting for purge to start
2020-04-15 22:54:26 9778 [Note] InnoDB: 5.6.22 started; log sequence number 0
A random root password has been set. You will find it in '/root/.mysql_secret'.
2020-04-15 22:54:26 9778 [Note] Binlog end
2020-04-15 22:54:26 9778 [Note] InnoDB: FTS optimize thread exiting.
2020-04-15 22:54:26 9778 [Note] InnoDB: Starting shutdown...
2020-04-15 22:54:28 9778 [Note] InnoDB: Shutdown completed; log sequence number 1625977
2020-04-15 22:54:28 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-04-15 22:54:28 9800 [Note] InnoDB: Using atomics to ref count buffer pool pages
2020-04-15 22:54:28 9800 [Note] InnoDB: The InnoDB memory heap is disabled
2020-04-15 22:54:28 9800 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-04-15 22:54:28 9800 [Note] InnoDB: Memory barrier is not used
2020-04-15 22:54:28 9800 [Note] InnoDB: Compressed tables use zlib 1.2.3
2020-04-15 22:54:28 9800 [Note] InnoDB: Using Linux native AIO
2020-04-15 22:54:28 9800 [Note] InnoDB: Not using CPU crc32 instructions
2020-04-15 22:54:28 9800 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2020-04-15 22:54:28 9800 [Note] InnoDB: Completed initialization of buffer pool
2020-04-15 22:54:28 9800 [Note] InnoDB: Highest supported file format is Barracuda.
2020-04-15 22:54:28 9800 [Note] InnoDB: 128 rollback segment(s) are active.
2020-04-15 22:54:28 9800 [Note] InnoDB: Waiting for purge to start
2020-04-15 22:54:28 9800 [Note] InnoDB: 5.6.22 started; log sequence number 1625977
2020-04-15 22:54:28 9800 [Note] Binlog end
2020-04-15 22:54:28 9800 [Note] InnoDB: FTS optimize thread exiting.
2020-04-15 22:54:28 9800 [Note] InnoDB: Starting shutdown...
2020-04-15 22:54:30 9800 [Note] InnoDB: Shutdown completed; log sequence number 1625987
A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in '/root/.mysql_secret'.
You must change that password on your first connect,
no other statement but 'SET PASSWORD' will be accepted.
See the manual for the semantics of the 'password expired' flag.
Also, the account for the anonymous user has been removed.
In addition, you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test database.
This is strongly recommended for production servers.
See the manual for more instructions.
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 /usr/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
獲取mysql初始化登錄密碼
cat /root/.mysql_secret
# The random password set for the root user at Wed Apr 15 22:54:26 2020 (local time): 20M5kGFxnH3NQB1g
6. 安裝客戶端
rpm -ivh MySQL-client-5.6.22-1.el6.i686.rpm
error: Failed dependencies:
libncurses.so.5 is needed by MySQL-client-5.6.22-1.el6.i686
libtinfo.so.5 is needed by MySQL-client-5.6.22-1.el6.i686
需要安裝相應(yīng)的依賴
yum -y install libncurses.so.5
yum -y install libtinfo.so.5
[root@localhost mysql]# rpm -ivh MySQL-client-5.6.22-1.el6.i686.rpm
準(zhǔn)備中... ################################# [100%]
正在升級/安裝...
1:MySQL-client-5.6.22-1.el6 ################################# [100%]
7. 啟動(dòng)mysql
- 命令
service mysql start
- 執(zhí)行結(jié)果
Starting MySQL. SUCCESS!
8. 將mysql加到系統(tǒng)服務(wù)中并設(shè)置開機(jī)啟動(dòng)
加入系統(tǒng)服務(wù):
chkconfig --add mysql
開機(jī)自啟動(dòng):
chkconfig mysql on
9. 登錄mysql
mysql -uroot -p20M5kGFxnH3NQB1g
10. 修改mysql密碼
mysql> set password = password ('123456');
11. 開啟mysql的遠(yuǎn)程登錄權(quán)限
mysql> grant all privileges on *.* to 'root'@'%' identified by '123456';
刷新
mysql> flush privileges;
13. 開放對外訪問3306端口
/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
永久開放3306端口
firewall-cmd --permanent --zone=public --add-port=3306/tcp
14. 查看防火墻開放的端口
firewall-cmd --list-ports
15. 宿主機(jī)使用Navicat Premium
工具遠(yuǎn)程連接mysql
16. rpm安裝mysql默認(rèn)的目錄
[root@localhost bin]# find / -name mysql
/run/lock/subsys/mysql
/etc/rc.d/init.d/mysql
/etc/logrotate.d/mysql
/etc/selinux/targeted/active/modules/100/mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/bin/mysql
/usr/lib/mysql
/usr/lib64/mysql
/usr/share/mysql
/usr/local/mysql
數(shù)據(jù)文件:/var/lib/mysql/
配置文件模板:/usr/share/mysql
mysql客戶端工具目錄:/usr/bin
日志目錄:/var/log/
pid陵且,sock文件目錄:/tmp/
配置文件會(huì)放在/etc
下
17. mysql數(shù)據(jù)庫的卸載
rpm -ev MySQL-server-5.6.22-1.el6.i686
rpm -ev MySQL-client-5.6.22-1.el6.i686
18. 修改my-default.cnf的位置并命名為my.cnf
cp /usr/share/mysql/my-default.cnf /etc/my.cnf #移動(dòng)MySQL配置文件的位置
具體如何修改my.cnf配置杜顺,請自行查詢my.cnf配置說明文檔
19. mysql的常用命令
開啟mysql:
service mysql start
重啟mysql:
service mysql restart
-
關(guān)閉mysql:
service mysql stop
以下操作需登錄:
- 顯示數(shù)據(jù)庫列表:
show databases;
- 創(chuàng)建數(shù)據(jù)庫:
create database 數(shù)據(jù)庫名;
- 刪除數(shù)據(jù)庫:
drop database 數(shù)據(jù)庫名;
- 選擇數(shù)據(jù)庫:
use 數(shù)據(jù)庫名;
- 顯示庫中的所有表:
show tables;
- 顯示數(shù)據(jù)表結(jié)構(gòu):
describe 數(shù)據(jù)表名;
- 顯示數(shù)據(jù)庫列表:
20. mysql的備份
導(dǎo)出數(shù)據(jù)庫blog 的命令
mysqldump -uroot -p123456 --databases blog > /tmp/test_blog .sql;
報(bào)以下警告:
Warning: Using a password on the command line interface can be insecure.
原因:這是因?yàn)樵诿钚薪缑嫔鲜褂妹艽a是不安全的
解決辦法:
- 修改 my.cnf文件财搁,添加以下內(nèi)容:
vi /etc/my.cnf
[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
host = localhost
user =root
password ='123456'
- 修改備份命令
導(dǎo)出指定數(shù)據(jù)庫:mysqldump --defaults-extra-file=/etc/my.cnf 數(shù)據(jù)庫名 >/tmp/test_db.sql ;
21. 解決導(dǎo)入數(shù)據(jù)包含中文
建議高版本的MySQL使用character-set-server,而不要使用default-character-set=utf8
- 解決辦法:
vi /etc/my.cnf
[client]
default-character-set=utf8
[mysqld]
character-set-server=utf8
2.設(shè)置好后查看字符編碼
mysql> SHOW VARIABLES LIKE 'char%';
22. 通過sql文件導(dǎo)入數(shù)據(jù)庫
mysql --defaults-extra-file=/etc/my.cnf blog < /tmp/blog.sql
mysql> use blog;
Database changed
mysql> show tables;
+--------------------+
| Tables_in_blog |
+--------------------+
| blog_article |
| blog_captcha |
| blog_comment |
| blog_label |
| blog_log |
| blog_set_label |
| blog_set_sort |
| blog_sort |
| bolg_user |
| label_link_article |
| sort_link_article |
| user_link_articles |
+--------------------+
12 rows in set (0.00 sec)