下载地址
- 地址 (提取码: mubi)
- 名称:
MySQL-5.6.22-1.el6.i686.rpm-bundle.tar
前置条件
新建虚拟机时最好给4G~8G的内存,不然最后启动mysql时会因为内存不够而报错
安装步骤
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
默认上传的位置
[root@localhost ~]# ls
anaconda-ks.cfg MySQL-5.6.22-1.el6.i686.rpm-bundle.tar
移动到/usr/local/mysql
下
[root@localhost ~]# mv MySQL-5.6.22-1.el6.i686.rpm-bundle.tar /usr/local/mysql
2. 查看是否已经安装mysql
rpm -qa | grep -i mysql
3. 解压tar文件
进入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
- 执行结果
[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中,默认的数据库已更新为了Mariadb,而非 MySQL,所以执行
yum install mysql
命令只是更新Mariadb数据库,并不会安装 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 数据库
rpm -qa | grep -i mariadb
卸载已安装的 Mariadb 数据库
rpm -ev mariadb-libs-5.5.64-1.el7.x86_64
5. 安装依赖组件
安装服务端时: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
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
由上面的错误可以看出我们需要安装相应的依赖
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
列出资源库中特定的可以安装或已经安装的rpm包的列表
libc.so.6,该库对应的软件包名称为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
再次运行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个
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
最后安装服务端: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
准备中... ################################# [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
需要安装相应的依赖
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
准备中... ################################# [100%]
正在升级/安装...
1:MySQL-client-5.6.22-1.el6 ################################# [100%]
7. 启动mysql
- 命令
service mysql start
- 执行结果
Starting MySQL. SUCCESS!
8. 将mysql加到系统服务中并设置开机启动
加入系统服务:
chkconfig --add mysql
开机自启动:
chkconfig mysql on
9. 登录mysql
mysql -uroot -p20M5kGFxnH3NQB1g
10. 修改mysql密码
mysql> set password = password ('123456');
11. 开启mysql的远程登录权限
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. 宿主机使用Navicat Premium
工具远程连接mysql
16. rpm安装mysql默认的目录
[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
数据文件:/var/lib/mysql/
配置文件模板:/usr/share/mysql
mysql客户端工具目录:/usr/bin
日志目录:/var/log/
pid,sock文件目录:/tmp/
配置文件会放在/etc
下
17. mysql数据库的卸载
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 #移动MySQL配置文件的位置
具体如何修改my.cnf配置,请自行查询my.cnf配置说明文档
19. mysql的常用命令
开启mysql:
service mysql start
重启mysql:
service mysql restart
-
关闭mysql:
service mysql stop
以下操作需登录:
- 显示数据库列表:
show databases;
- 创建数据库:
create database 数据库名;
- 删除数据库:
drop database 数据库名;
- 选择数据库:
use 数据库名;
- 显示库中的所有表:
show tables;
- 显示数据表结构:
describe 数据表名;
- 显示数据库列表:
20. mysql的备份
导出数据库blog 的命令
mysqldump -uroot -p123456 --databases blog > /tmp/test_blog .sql;
报以下警告:
Warning: Using a password on the command line interface can be insecure.
原因:这是因为在命令行界面上使用密码是不安全的
解决办法:
- 修改 my.cnf文件,添加以下内容:
vi /etc/my.cnf
[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
host = localhost
user =root
password ='123456'
- 修改备份命令
导出指定数据库:mysqldump --defaults-extra-file=/etc/my.cnf 数据库名 >/tmp/test_db.sql ;
21. 解决导入数据包含中文
建议高版本的MySQL使用character-set-server,而不要使用default-character-set=utf8
- 解决办法:
vi /etc/my.cnf
[client]
default-character-set=utf8
[mysqld]
character-set-server=utf8
2.设置好后查看字符编码
mysql> SHOW VARIABLES LIKE 'char%';
22. 通过sql文件导入数据库
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)