图片 3

在centos中装置mysql详细步骤表达,rpm包安装配备文档

Last login: Sun Dec 24 04:55:59
2017

一、卸载自带mysql,删除MySQL的lib库,服务文件

[root@localhost ~]#rpm -qa|grep mysql
qt-mysql-4.6.2-26.el6_4.x86_64
mysql-5.1.71-1.el6.x86_64
mysql-libs-5.1.71-1.el6.x86_64
mysql-devel-5.1.71-1.el6.x86_64
mysql-server-5.1.71-1.el6.x86_64

[root@localhost ~]# rpm -e –nodeps
qt-mysql-4.6.2-26.el6_4.x86_64
[root@localhost ~]# rpm -e –nodeps mysql-5.1.71-1.el6.x86_64
[root@localhost ~]# rpm -e –nodeps
mysql-libs-5.1.71-1.el6.x86_64
[root@localhost ~]# rpm -e –nodeps
mysql-devel-5.1.71-1.el6.x86_64
[root@localhost ~]# rpm -e –nodeps
mysql-server-5.1.71-1.el6.x86_64
[root@localhost ~]# rpm -qa|grep mysql
[root@localhost ~]#

清除所有mysql相关文件:
[root@localhost ~]#find / -name mysql
/usr/lib64/perl5/DBD/mysql
/usr/lib64/perl5/auto/DBD/mysql
/usr/share/mysql

[root@localhost ~]#rm –rf /usr/lib64/perl5/DBD/mysql
[root@localhost ~]#rm –rf /usr/lib64/perl5/auto/DBD/mysql
[root@localhost ~]#rm –rf /usr/share/mysql

查看是否有残留文件:
[root@localhost ~]#rpm -qa | grep mysql

1、安装依赖

[root@node001 ~]# yum install -y perl
Loaded plugins: fastestmirror
Loading mirror speeds from cached
hostfile
base | 3.7 kB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
Setting up Install Process
Package 4:perl-5.10.1-144.el6.x86_64
already installed and latest version
Nothing to do

二、安装MySQL

2、 卸载旧版本的mysql及插件

[root@node001 ~]# rpm -qa | grep mysql
mysql-5.1.73-8.el6_8.x86_64
mysql-libs-5.1.73-8.el6_8.x86_64
mysql-server-5.1.73-8.el6_8.x86_64

[root@node001 ~]# rpm -e mysql-5.1.73-8.el6_8.x86_64
–nodeps

[root@node001 ~]# rpm -e
mysql-libs-5.1.73-8.el6_8.x86_64 –nodeps

[root@node001 ~]# rpm -e
mysql-server-5.1.73-8.el6_8.x86_64 –nodeps

(–nodeps:忽略其他依赖,直接卸载)

1.复制mysql安装包到安装目录

准备源码包:MySQL-5.6.36-1.linux_glibc2.5.i386.rpm-bundle.tar
将源码包以二进制方式上传到/usr/appsoft/software目录下

3、 安装rpm(4个)

安装包

图片 1

[root@node001 ~]# tar zxvf mysql.tar.gz
MySQL-client-5.6.28-1.el6.x86_64.rpm
MySQL-devel-5.6.28-1.el6.x86_64.rpm
MySQL-server-5.6.28-1.el6.x86_64.rpm
numactl-2.0.9-2.el6.x86_64.rpm

 

[root@node001 ~]# rpm -ivh
MySQL-client-5.6.28-1.el6.x86_64.rpm
warning: MySQL-client-5.6.28-1.el6.x86_64.rpm: Header V3 DSA/SHA1
Signature, key ID 5072e1f5: NOKEY
Preparing…
###########################################
[100%]
1:MySQL-client
###########################################
[100%]

[root@node001 ~]# rpm -ivh MySQL-devel-5.6.28-1.el6.x86_64.rpm

warning:
MySQL-devel-5.6.28-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key
ID 5072e1f5: NOKEY
Preparing…
###########################################
[100%]
1:MySQL-devel
###########################################
[100%]

[root@node001 ~]# rpm -ivh numactl-2.0.9-2.el6.x86_64.rpm

Preparing…
###########################################
[100%]
1:numactl
###########################################
[100%]

[root@node001 ~]# rpm -ivh
MySQL-server-5.6.28-1.el6.x86_64.rpm
warning:
MySQL-server-5.6.28-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key
ID 5072e1f5: NOKEY
Preparing…
###########################################
[100%]
1:MySQL-server
###########################################
[100%]
2017-12-24 05:39:08 0 [Warning]
TIMESTAMP with implicit DEFAULT value is deprecated. Please use
–explicit_defaults_for_timestam
p server option (see documentation for
more details).2017-12-24 05:39:08 0 [Note] /usr/sbin/mysqld (mysqld
5.6.28) starting as process 1287 …
2017-12-24 05:39:08 1287 [Note] InnoDB:
Using atomics to ref count buffer pool pages
2017-12-24 05:39:08 1287 [Note] InnoDB:
The InnoDB memory heap is disabled
2017-12-24 05:39:08 1287 [Note] InnoDB:
Mutexes and rw_locks use GCC atomic builtins
2017-12-24 05:39:08 1287 [Note] InnoDB:
Memory barrier is not used
2017-12-24 05:39:08 1287 [Note] InnoDB:
Compressed tables use zlib 1.2.3
2017-12-24 05:39:08 1287 [Note] InnoDB:
Using Linux native AIO
2017-12-24 05:39:08 1287 [Note] InnoDB:
Using CPU crc32 instructions
2017-12-24 05:39:08 1287 [Note] InnoDB:
Initializing buffer pool, size = 128.0M
2017-12-24 05:39:08 1287 [Note] InnoDB:
Completed initialization of buffer pool
2017-12-24 05:39:08 1287 [Note] InnoDB:
The first specified data file ./ibdata1 did not exist: a new database to
be created

………………………..

The latest information about MySQL is
available on the web at

Support MySQL by buying support/licenses
at

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

2.解压安装包

[root@localhost ~]cd /usr/appsoft/software
[root@localhost software]# tar xvf
MySQL-5.6.36-1.linux_glibc2.5.i386.rpm-bundle.tar

将解压出以下文件:
MySQL的测试组件MySQL-shared-5.6.22-1.linux_glibc2.5.i386.rpm
MySQL的共享库MySQL-shared-compat-5.6.22-1.linux_glibc2.5.i386.rpm
MySQL版本兼容的包MySQL-client-5.6.22-1.linux_glibc2.5.i386.rpm
MySQL客户端程序MySQL-devel-5.6.22-1.linux_glibc2.5.i386.rpm
MySQL的库和头文件MySQL-embedded-5.6.22-1.linux_glibc2.5.i386.rpm
MySQL的嵌入式程序MySQL-server-5.6.22-1.linux_glibc2.5.i386.rpm
MySQL服务端程序

4、上传mysql配置文件my.cnf

[root@node001 ~]# cd /etc

上传文件

图片 2

[root@node001 etc]# ls /etc/my.cnf
/etc/my.cnf

3.安装服务端

[root@localhost software]# rpm -ivh rpm -ivh
MySQL-server-5.6.36-1.rhel5.i386.rpm
warning: MySQL-server-5.6.36-1.rhel5.i386.rpm: Header V3 DSA/SHA1
Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
libaio.so.1 is needed by MySQL-server-5.6.36-1.rhel5.i386
libaio.so.1(LIBAIO_0.1) is needed by MySQL-server-5.6.36-1.rhel5.i386
libaio.so.1(LIBAIO_0.4) is needed by MySQL-server-5.6.36-1.rhel5.i386
libstdc++.so.6 is needed by MySQL-server-5.6.36-1.rhel5.i386
libstdc++.so.6(CXXABI_1.3) is needed by
MySQL-server-5.6.36-1.rhel5.i386
libstdc++.so.6(GLIBCXX_3.4) is needed by
MySQL-server-5.6.36-1.rhel5.i386
[root@ localhost software]# find / -name libaio.so.1
/lib64/libaio.so.1
[root@ localhost software]# find / -name libstdc++.so.6
/usr/lib64/libstdc++.so.6
如果出现以上错误说明缺少libaio.so.1和libstdc++.so.6
将libaio-0.3.107-10.el6.i686.rpm和libstdc++-4.4.7-4.el6.i686.rpm上传到/usr/appsoft/software并安装。

安装libaio-0.3.107-10.el6.i686.rpm:
[root@ localhost software]# rpm -ivh libaio-0.3.107-10.el6.i686.rpm
warning: libaio-0.3.107-10.el6.i686.rpm: Header V3 RSA/SHA256 Signature,
key ID fd431d51: NOKEY
Preparing…
###########################################
[100%]
1:libaio
###########################################
[100%]

安装libstdc++-4.4.7-4.el6.i686.rpm:
[root@ localhost software]# rpm -ivh libstdc++-4.4.7-4.el6.i686.rpm
warning: libstdc++-4.4.7-4.el6.i686.rpm: Header V3 RSA/SHA256 Signature,
key ID fd431d51: NOKEY
Preparing…
###########################################
[100%]
1:libstdc++
###########################################
[100%]
以上两个rpm包安装完之后重新安装mysql服务端:
[root@localhost software] warning:
MySQL-server-5.6.36-1.rhel5.i386.rpm: Header V3 DSA/SHA1 Signature, key
ID 5072e1f5: NOKEY
Preparing…
###########################################
[100%]
1:MySQL-server
###########################################
[100%]
2017-06-19 15:05:34 0 [Warning] TIMESTAMP with implicit DEFAULT value
is deprecated. Please use –explicit_defaults_for_timestamp server
option (see documentation for more details).
2017-06-19 15:05:34 0 [Note] Ignoring –secure-file-priv value as
server is running with –bootstrap.
2017-06-19 15:05:34 0 [Note] /usr/sbin/mysqld (mysqld 5.6.36) starting
as process 2702 …
2017-06-19 15:05:34 2702 [Note] InnoDB: Using mutexes to ref count
buffer pool pages
2017-06-19 15:05:34 2702 [Note] InnoDB: The InnoDB memory heap is
disabled
2017-06-19 15:05:34 2702 [Note] InnoDB: Mutexes and rw_locks use
InnoDB’s own implementation
2017-06-19 15:05:34 2702 [Note] InnoDB: Memory barrier is not used
2017-06-19 15:05:34 2702 [Note] InnoDB: Compressed tables use zlib
1.2.3
2017-06-19 15:05:34 2702 [Note] InnoDB: Using Linux native AIO
2017-06-19 15:05:34 2702 [Note] InnoDB: Not using CPU crc32
instructions
2017-06-19 15:05:34 2702 [Note] InnoDB: Initializing buffer pool, size
= 128.0M
2017-06-19 15:05:34 2702 [Note] InnoDB: Completed initialization of
buffer pool
2017-06-19 15:05:34 2702 [Note] InnoDB: The first specified data file
./ibdata1 did not exist: a new database to be created!
2017-06-19 15:05:34 2702 [Note] InnoDB: Setting file ./ibdata1 size to
12 MB
2017-06-19 15:05:34 2702 [Note] InnoDB: Database physically writes the
file full: wait…
2017-06-19 15:05:34 2702 [Note] InnoDB: Setting log file
./ib_logfile101 size to 48 MB
2017-06-19 15:05:34 2702 [Note] InnoDB: Setting log file
./ib_logfile1 size to 48 MB
2017-06-19 15:05:35 2702 [Note] InnoDB: Renaming log file
./ib_logfile101 to ./ib_logfile0
2017-06-19 15:05:35 2702 [Warning] InnoDB: New log files created,
LSN=45781
2017-06-19 15:05:35 2702 [Note] InnoDB: Doublewrite buffer not found:
creating new
2017-06-19 15:05:35 2702 [Note] InnoDB: Doublewrite buffer created
2017-06-19 15:05:35 2702 [Note] InnoDB: 128 rollback segment(s) are
active.
2017-06-19 15:05:35 2702 [Warning] InnoDB: Creating foreign key
constraint system tables.
2017-06-19 15:05:35 2702 [Note] InnoDB: Foreign key constraint system
tables created
2017-06-19 15:05:35 2702 [Note] InnoDB: Creating tablespace and
datafile system tables.
2017-06-19 15:05:35 2702 [Note] InnoDB: Tablespace and datafile system
tables created.
2017-06-19 15:05:35 2702 [Note] InnoDB: Waiting for purge to start
2017-06-19 15:05:35 2702 [Note] InnoDB: 5.6.36 started; log sequence
number 0
A random root password has been set. You will find it in
‘/root/.mysql_secret’.
2017-06-19 15:05:35 2702 [Note] Binlog end
2017-06-19 15:05:35 2702 [Note] InnoDB: FTS optimize thread exiting.
2017-06-19 15:05:35 2702 [Note] InnoDB: Starting shutdown…
2017-06-19 15:05:37 2702 [Note] InnoDB: Shutdown completed; log
sequence number 1625977

2017-06-19 15:05:37 0 [Warning] TIMESTAMP with implicit DEFAULT value
is deprecated. Please use –explicit_defaults_for_timestamp server
option (see documentation for more details).
2017-06-19 15:05:37 0 [Note] Ignoring –secure-file-priv value as
server is running with –bootstrap.
2017-06-19 15:05:37 0 [Note] /usr/sbin/mysqld (mysqld 5.6.36) starting
as process 2724 …
2017-06-19 15:05:37 2724 [Note] InnoDB: Using mutexes to ref count
buffer pool pages
2017-06-19 15:05:37 2724 [Note] InnoDB: The InnoDB memory heap is
disabled
2017-06-19 15:05:37 2724 [Note] InnoDB: Mutexes and rw_locks use
InnoDB’s own implementation
2017-06-19 15:05:37 2724 [Note] InnoDB: Memory barrier is not used
2017-06-19 15:05:37 2724 [Note] InnoDB: Compressed tables use zlib
1.2.3
2017-06-19 15:05:37 2724 [Note] InnoDB: Using Linux native AIO
2017-06-19 15:05:37 2724 [Note] InnoDB: Not using CPU crc32
instructions
2017-06-19 15:05:37 2724 [Note] InnoDB: Initializing buffer pool, size
= 128.0M
2017-06-19 15:05:37 2724 [Note] InnoDB: Completed initialization of
buffer pool
2017-06-19 15:05:37 2724 [Note] InnoDB: Highest supported file format
is Barracuda.
2017-06-19 15:05:37 2724 [Note] InnoDB: 128 rollback segment(s) are
active.
2017-06-19 15:05:37 2724 [Note] InnoDB: Waiting for purge to start
2017-06-19 15:05:37 2724 [Note] InnoDB: 5.6.36 started; log sequence
number 1625977
2017-06-19 15:05:37 2724 [Note] Binlog end
2017-06-19 15:05:37 2724 [Note] InnoDB: FTS optimize thread exiting.
2017-06-19 15:05:37 2724 [Note] InnoDB: Starting shutdown…
2017-06-19 15:05:39 2724 [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

The latest information about MySQL is available on the web at

Support MySQL by buying support/licenses at

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

5、初始化

[root@node001 etc]# /usr/bin/mysql_install_db
Installing MySQL system
tables…2017-12-24 05:41:57 0 [Note] /usr/sbin/mysqld (mysqld
5.6.28-log) starting as process 1353 …
2017-12-24 05:41:57 1353 [Note] InnoDB:
Using atomics to ref count buffer pool pages
2017-12-24 05:41:57 1353 [Note] InnoDB:
The InnoDB memory heap is disabled
2017-12-24 05:41:57 1353 [Note] InnoDB:
Mutexes and rw_locks use GCC atomic builtins
2017-12-24 05:41:57 1353 [Note] InnoDB:
Memory barrier is not used
2017-12-24 05:41:57 1353 [Note] InnoDB:
Compressed tables use zlib 1.2.3
2017-12-24 05:41:57 1353 [Note] InnoDB:
Using Linux native AIO
2017-12-24 05:41:57 1353 [Note] InnoDB:
Using CPU crc32 instructions
2017-12-24 05:41:57 1353 [Note] InnoDB:
Initializing buffer pool, size = 64.0M
2017-12-24 05:41:57 1353 [Note] InnoDB:
Completed initialization of buffer pool
2017-12-24 05:41:57 1353 [Note] InnoDB:
Highest supported file format is Barracuda.
2017-12-24 05:41:57 1353 [Warning]
InnoDB: Resizing redo log from 2*3072 to 3*2048 pages,
LSN=1625987
………………..

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

 

4.安装库文件

[root@ localhost software]# rpm -ivh
MySQL-devel-5.6.36-1.rhel5.i386.rpm
warning: MySQL-devel-5.6.36-1.rhel5.i386.rpm: Header V3 DSA/SHA1
Signature, key ID 5072e1f5: NOKEY
Preparing…
###########################################
[100%]
1:MySQL-devel
###########################################
[100%]

6、  启动mysql

 

[root@node001 etc]# service mysql start
Starting MySQL……. SUCCESS!

 

 

5.安装客户端

[root@ localhost software]# rpm -ivh
MySQL-client-5.6.35-1.rhel5.i386.rpm
warning: MySQL-client-5.6.35-1.rhel5.i386.rpm: Header V3 DSA/SHA1
Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
libncurses.so.5 is needed by MySQL-client-5.6.35-1.rhel5.i386
报上面的错误说明缺少libncurses.so.5。
将ncurses-libs-5.7-3.20090208.el6.i686.rpm上传至/usr/appsoft/software
[root@localhost software]# rpm -ivh
ncurses-libs-5.7-3.20090208.el6.i686.rpm
warning: ncurses-libs-5.7-3.20090208.el6.i686.rpm: Header V3 RSA/SHA256
Signature, key ID fd431d51: NOKEY
Preparing…
###########################################
[100%]
1:ncurses-libs
###########################################
[100%]
重新安装客户端:# rpm -ivh MySQL-client-5.6.35-1.rhel5.i386.rpm
warning: MySQL-client-5.6.35-1.rhel5.i386.rpm: Header V3 DSA/SHA1
Signature, key ID 5072e1f5: NOKEY
Preparing…
###########################################
[100%]
1:MySQL-client
###########################################
[100%]

MySQL默认安装路径:
a.数据库目录: /var/lib/mysql/
b.配置文件: /usr/share/mysql
c.相关命令: /usr/bin
d.启动脚本: /etc/rc.d/init.d/

7、重置密码

查看初始化密码

[root@node001 etc]# cat /root/.mysql_secret
# The random password set for the root
user at Sun Dec 24 05:39:11 2017 (local time):
DMBe85LznCxRo16N

图片 3

 

[root@node001 etc]# mysql -u root -pDMBe85LznCxRo16N
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.28-log

Copyright (c) 2000, 2015, 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>
set password=password(‘mysql’);
Query OK, 0 rows affected (0.00
sec)

mysql>
show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| mysql |
| performance_schema |
| test |
+——————–+
4 rows in set (0.00 sec)

6.修改配置文件,将MySQL的配置文件拷贝到/etc目录下。

[root@localhost mysql]# cp /usr/share/mysql/my-default.cnf
/etc/my.cnf
修改/etc/my.cnf,让数据库不区分表名大小写(此处错误会导致‘创建其他表’时错误)
在[mysqld]配置项下加入以下语句
lower_case_table_names=1
赋予用户写二进制备份数据的权限(创建触发器时必须有这权限)
log_bin_trust_function_creators=1
默认断开连接时间设为1年
wait_timeout=31536000
interactive_timeout=31536000
解决连接数据库过慢问题:
在[mysqld]下加入以下内容
character-set-server = utf8
character-set-filesystem = utf8
skip-name-resolve
不需要存日志的时候注释掉log-bin=mysql-bin
如果你需要日志,最好控制一下这些日志文件保留的天数,可以通过下面的配置设定日志文件保留的天数:
expire_logs_days = 7
表示保留7天的日志,这样老日志会自动被清理掉。

8、远程授权

 

原因:默认远程无法连接

 

授权命令:

 

mysql> grant all privileges on *.* to ‘root’@’%’
identified by ‘mysql’ with grant option;
Query OK, 0 rows affected (0.00
sec)

mysql>
flush privileges;
Query OK, 0 rows affected (0.01
sec)

7.初始化MySQL

[root@localhost mysql]# /usr/bin/mysql_install_db

8.启动MySQL

[root@localhost mysql]# service mysql start
Starting MySQL…. SUCCESS!

检测mysql 3306是否安打开
[root@localhost mysql]# netstat -nattcp |grep 3306
0 0 :::3306 :::* LISTEN

9.从.mysql_secret查看root账号初始密码

[root@localhost mysql]# cat /root/.mysql_secret
The random password set for the root user at Thu Dec 18 21:08:44 2014
(local time): vuN8xfuKTRnmqX3I
其中vuN8xfuKTRnmqX3I为root账号的初始密码。

10.使用默认密码登陆mysql

[root@localhost mysql]# mysql -u root -pvuN8xfuKTRnmqX3I
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 4Server version:
5.6.22Copyright (c) 2000, 2014, Oracle and/or its affiliates.
All rights reserved.Oracle is a registered trademark of Oracle
Corporation and/or itsaffiliates. Other names may be trademarks of their
respectiveowners.
Type ‘help;’ or ‘/h’ for help. Type ‘/c’ to clear the current input
statement.mysql>

修改默认密码:
mysql> set password = password(‘iesapp’);
Query OK, 0 rows affected (0.02 sec)
退出mysql
mysql> quit;
Bye

11.添加自启动服务

[root@localhost ~]# chkconfig –add mysql
[root@localhost ~]# chkconfig mysql on

12.创建数据库

mysql –u root –p iesapp
create database ms DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;
create database ls DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;

设置访问权限(所有机器都可访问)

GRANT ALL PRIVILEGES ON 数据库名 TO
‘用户名’@’%’ IDENTIFIED BY
‘密码’;

flush privileges ;
quit;
重启mysql服务即可使用
service mysql restart;

关闭防火墙
[root@localhost ~]# service iptables stop
iptables: Flushing firewall rules:
[ OK ]iptables: Setting chains to policy ACCEPT: filter
[ OK ]iptables: Unloading modules:
[ OK ]

[root@localhost ~]# service iptables status
iptables: Firewall is not running.