一、mysql下载
mysql5.6
官方下载地址 https://dev.mysql.com/downloads/mysql/5.6.html#downloads
选择mysql的版本,操作系统平台以及操作系统的版本
二、解压mysql安装包
2.1新建目录mysql-install-package并将mysql的安装包拷贝到新建的目录中
[hadoop@Master ~]$
mkdir mysql-install-package
[hadoop@Master ~]$
cp MySQL-5.6.38-1.el6.x86_64.rpm-bundle.tar mysql-install-package/
[hadoop@Master ~]$
2.2进入目录mysql-install-package,执行命令
tar -xvf MySQL-5.6.38-1.el6.x86_64.rpm-bundle.tar
,将压缩包进行解压缩
[hadoop@Master ~]$ cd mysql-install-package/
[hadoop@Master mysql-install-package]$ ls
MySQL-5.6.38-1.el6.x86_64.rpm-bundle.tar
[hadoop@Master mysql-install-package]$ tar -xvf MySQL-5.6.38-1.el6.x86_64.rpm-bundle.tar
MySQL-shared-5.6.38-1.el6.x86_64.rpm
MySQL-devel-5.6.38-1.el6.x86_64.rpm
MySQL-client-5.6.38-1.el6.x86_64.rpm
MySQL-test-5.6.38-1.el6.x86_64.rpm
MySQL-server-5.6.38-1.el6.x86_64.rpm
MySQL-embedded-5.6.38-1.el6.x86_64.rpm
MySQL-shared-compat-5.6.38-1.el6.x86_64.rpm
三、
以RPM方式安装MySQL
3.1在RHEL系统中安装mysql需要先运行MySQL-shared-5.5.58-1.el6.x86_64.rpm,这个兼容包,然后才能安装server,先后执行以下命令进行mysql的安装
1.yum install MySQL-shared-5.6.38-1.el6.x86_64.rpm #安装mysql兼容包
2.yum install MySQL-server-5.6.38-1.el6.x86_64.rpm #安装mysql的服务器程序
3.yum install MySQL-client-5.6.38-1.el6.x86_64.rpm #安装mysql的客户端程序
4.yum install MySQL-devel-5.6.38-1.el6.x86_64.rpm #安装mysql的库和头文件
3.2安装过程记录
安装时,mysql会自动为root用户生成一个随机登录密码,该密码保存在文件/root/
.mysql_secret中,并提示我们在登录数据库后对密码进行修改
[root@Master mysql-install-package]#
yum install MySQL-shared-5.6.38-1.el6.x86_64.rpm
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Install Process
Examining MySQL-shared-5.6.38-1.el6.x86_64.rpm: MySQL-shared-5.6.38-1.el6.x86_64
Marking MySQL-shared-5.6.38-1.el6.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package MySQL-shared.x86_64 0:5.6.38-1.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================================================================
Package Arch Version Repository Size
================================================================================================================================
Installing:
MySQL-shared x86_64 5.6.38-1.el6 /MySQL-shared-5.6.38-1.el6.x86_64 8.6 M
Transaction Summary
================================================================================================================================
Install 1 Package(s)
Total size: 8.6 M
Installed size: 8.6 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
Installing : MySQL-shared-5.6.38-1.el6.x86_64 1/1
Verifying : MySQL-shared-5.6.38-1.el6.x86_64 1/1
Installed:
MySQL-shared.x86_64 0:5.6.38-1.el6
Complete!
[root@Master mysql-install-package]#
yum install MySQL-server-5.6.38-1.el6.x86_64.rpm
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Install Process
Examining MySQL-server-5.6.38-1.el6.x86_64.rpm: MySQL-server-5.6.38-1.el6.x86_64
Marking MySQL-server-5.6.38-1.el6.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package MySQL-server.x86_64 0:5.6.38-1.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================================================================
Package Arch Version Repository Size
================================================================================================================================
Installing:
MySQL-server x86_64 5.6.38-1.el6 /MySQL-server-5.6.38-1.el6.x86_64 244 M
Transaction Summary
================================================================================================================================
Install 1 Package(s)
Total size: 244 M
Installed size: 244 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : MySQL-server-5.6.38-1.el6.x86_64 1/1
2017-10-17 20:38:11 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-10-17 20:38:11 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2017-10-17 20:38:11 0 [Note] /usr/sbin/mysqld (mysqld 5.6.38) starting as process 15616 ...
2017-10-17 20:38:11 15616 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-10-17 20:38:11 15616 [Note] InnoDB: The InnoDB memory heap is disabled
2017-10-17 20:38:11 15616 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-10-17 20:38:11 15616 [Note] InnoDB: Memory barrier is not used
2017-10-17 20:38:11 15616 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-10-17 20:38:11 15616 [Note] InnoDB: Using Linux native AIO
2017-10-17 20:38:11 15616 [Note] InnoDB: Using CPU crc32 instructions
2017-10-17 20:38:11 15616 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-10-17 20:38:11 15616 [Note] InnoDB: Completed initialization of buffer pool
2017-10-17 20:38:11 15616 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2017-10-17 20:38:11 15616 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2017-10-17 20:38:11 15616 [Note] InnoDB: Database physically writes the file full: wait...
2017-10-17 20:38:11 15616 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2017-10-17 20:38:11 15616 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2017-10-17 20:38:12 15616 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2017-10-17 20:38:12 15616 [Warning] InnoDB: New log files created, LSN=45781
2017-10-17 20:38:12 15616 [Note] InnoDB: Doublewrite buffer not found: creating new
2017-10-17 20:38:12 15616 [Note] InnoDB: Doublewrite buffer created
2017-10-17 20:38:12 15616 [Note] InnoDB: 128 rollback segment(s) are active.
2017-10-17 20:38:12 15616 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-10-17 20:38:12 15616 [Note] InnoDB: Foreign key constraint system tables created
2017-10-17 20:38:12 15616 [Note] InnoDB: Creating tablespace and datafile system tables.
2017-10-17 20:38:12 15616 [Note] InnoDB: Tablespace and datafile system tables created.
2017-10-17 20:38:12 15616 [Note] InnoDB: Waiting for purge to start
2017-10-17 20:38:12 15616 [Note] InnoDB: 5.6.38 started; log sequence number 0
2017-10-17 20:38:12 15616 [Note] Binlog end
2017-10-17 20:38:12 15616 [Note] InnoDB: FTS optimize thread exiting.
2017-10-17 20:38:12 15616 [Note] InnoDB: Starting shutdown...
2017-10-17 20:38:14 15616 [Note] InnoDB: Shutdown completed; log sequence number 1625977
A random root password has been set. You will find it in
'/root/.mysql_secret'.
2017-10-17 20:38:14 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-10-17 20:38:14 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2017-10-17 20:38:14 0 [Note] /usr/sbin/mysqld (mysqld 5.6.38) starting as process 15638 ...
2017-10-17 20:38:14 15638 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-10-17 20:38:14 15638 [Note] InnoDB: The InnoDB memory heap is disabled
2017-10-17 20:38:14 15638 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-10-17 20:38:14 15638 [Note] InnoDB: Memory barrier is not used
2017-10-17 20:38:14 15638 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-10-17 20:38:14 15638 [Note] InnoDB: Using Linux native AIO
2017-10-17 20:38:14 15638 [Note] InnoDB: Using CPU crc32 instructions
2017-10-17 20:38:14 15638 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-10-17 20:38:14 15638 [Note] InnoDB: Completed initialization of buffer pool
2017-10-17 20:38:14 15638 [Note] InnoDB: Highest supported file format is Barracuda.
2017-10-17 20:38:14 15638 [Note] InnoDB: 128 rollback segment(s) are active.
2017-10-17 20:38:14 15638 [Note] InnoDB: Waiting for purge to start
2017-10-17 20:38:14 15638 [Note] InnoDB: 5.6.38 started; log sequence number 1625977
2017-10-17 20:38:14 15638 [Note] Binlog end
2017-10-17 20:38:14 15638 [Note] InnoDB: FTS optimize thread exiting.
2017-10-17 20:38:14 15638 [Note] InnoDB: Starting shutdown...
2017-10-17 20:38:16 15638 [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
Verifying : MySQL-server-5.6.38-1.el6.x86_64 1/1
Installed:
MySQL-server.x86_64 0:5.6.38-1.el6
Complete!
[root@Master mysql-install-package]#
yum install MySQL-client-5.6.38-1.el6.x86_64.rpm
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Install Process
Examining MySQL-client-5.6.38-1.el6.x86_64.rpm: MySQL-client-5.6.38-1.el6.x86_64
Marking MySQL-client-5.6.38-1.el6.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package MySQL-client.x86_64 0:5.6.38-1.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================================================================
Package Arch Version Repository Size
================================================================================================================================
Installing:
MySQL-client x86_64 5.6.38-1.el6 /MySQL-client-5.6.38-1.el6.x86_64 83 M
Transaction Summary
================================================================================================================================
Install 1 Package(s)
Total size: 83 M
Installed size: 83 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : MySQL-client-5.6.38-1.el6.x86_64 1/1
Verifying : MySQL-client-5.6.38-1.el6.x86_64 1/1
Installed:
MySQL-client.x86_64 0:5.6.38-1.el6
Complete!
[root@Master mysql-install-package]#
yum install MySQL-devel-5.6.38-1.el6.x86_64.rpm
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Install Process
Examining MySQL-devel-5.6.38-1.el6.x86_64.rpm: MySQL-devel-5.6.38-1.el6.x86_64
Marking MySQL-devel-5.6.38-1.el6.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package MySQL-devel.x86_64 0:5.6.38-1.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================================================================
Package Arch Version Repository Size
================================================================================================================================
Installing:
MySQL-devel x86_64 5.6.38-1.el6 /MySQL-devel-5.6.38-1.el6.x86_64 20 M
Transaction Summary
================================================================================================================================
Install 1 Package(s)
Total size: 20 M
Installed size: 20 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : MySQL-devel-5.6.38-1.el6.x86_64 1/1
Verifying : MySQL-devel-5.6.38-1.el6.x86_64 1/1
Installed:
MySQL-devel.x86_64 0:5.6.38-1.el6
Complete!
四、mysql安装完成后,查看mysql的安装路径,启动、停止mysql服务
4.1查看mysql安装后相关的目录内容
[root@Master mysql-install-package]#
find / -name mysql
/var/lib/mysql
/var/lib/mysql/mysql
/etc/rc.d/init.d/mysql
/etc/logrotate.d/mysql
/usr/include/mysql
/usr/include/mysql/mysql
/usr/bin/mysql
/usr/lib64/mysql
/usr/share/mysql
4.2启动mysql服务
[root@Master mysql-install-package]# service mysql start
Starting MySQL.Logging to '/var/lib/mysql/Master.Hadoop.err'.
. SUCCESS!
4.3停止mysql服务
[root@Master mysql-install-package]# service mysql stop
Shutting down MySQL.. SUCCESS!
五、修改mysql的安装路径
改变mysql数据库的安装目录一般来说只要修改数据的存放目录即可,即修改目录
/var/lib/mysql/的存放路径,现将mysql数据存放目录修改为/usr/local/mysql
5.1数据库主要目录内容介绍
1、数据库目录
/var/lib/mysql/
2、配置文件
/usr/share/mysql(mysql.server命令及配置文件)mysql5.5之后的默认安装路径,mysql5.5之前的是/usr/local/mysql
3、相关命令
/usr/bin(mysqladmin mysqldump等命令)
4、启动脚本
/etc/rc.d/init.d/(启动脚本文件mysql的目录)
5.2
生成mysql.sock文件,并保存
因为在后面需要mysql.sock文件,该文件在mysql数据库服务启动的时候,会产生并存放在
/var/lib/mysql目录下
[root@Master mysql]#
service mysql start
Starting MySQL... SUCCESS!
[root@Master hadoop]#
cd /var/lib/mysql
[root@Master mysql]# ls
auto.cnf ib_logfile0 Master.Hadoop.err mysql performance_schema RPM_UPGRADE_MARKER-LAST
ibdata1 ib_logfile1 Master.Hadoop.pid
mysql.sock
RPM_UPGRADE_HISTORY test
5.3
把/var/lib/mysql整个目录保持权限复制到/usr/local
[root@Master mysql]#
cp -arp /var/lib/mysql /usr/local
[root@Master mysql]# service mysql stop
Shutting down MySQL.. SUCCESS!
5.4修改my.cnf文件
进入/etc目录下查找文件my.cnf文件是否存在,如果存在则直接进行修改,如果不存在,
则进入目录
/usr/share/mysql下执行命令
cp my-default.cnf /etc/my.cnf
然后使用vi修改my.cnf文件增加一下内容
datadir =/usr/local/mysql #mysql数据库的新目录
socket =/usr/local/mysql/mysql.sock
#知名mysql.sock的产生位置
[root@Master mysql]# vi /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
#datadir =
.....
# port = .....
# server_id = .....
#socket =
.....
datadir =/usr/local/mysql
socket =/usr/local/mysql/mysql.sock
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
5.5
最后做一个mysql.sock的软连接:
[root@Master mysql]#
ln -s /usr/local/mysql/mysql.sock /var//lib/mysql/mysql.sock
经过这五步操作,修改mysql的安装目录的操作就完成了,下面就登录mysql进行测试一下了
六、启动mysql服务,使用root用户登录mysql数据库
6.1.启动mysql数据库的服务
[root@Master mysql]# service mysql start
Starting MySQL SUCCESS!
6.2.查看mysql为我们随机生成的登录密码
MySQL的安装日志信息中,你会看到MySQL生成了root用户的随机密码(如下截图所示),并将这个随机密码放置在/root/.mysql_secret中。并且强制在第一次登陆时修改root用户的密码。Mysql 5.6及以后版本出处于安全考虑,root密码不为空。所以在MySQL的安装过程中,会生成一个随机密码,该文件为隐藏文件,
[root@Master ~]# cd /root
[root@Master ~]# pwd
/root
[root@Master ~]# ls -la
total 124
dr-xr-x---. 4 root root 4096 Oct 17 20:38 .
dr-xr-xr-x. 22 root root 4096 Oct 16 01:07 ..
-rw-------. 1 root root 2631 Sep 29 04:38 anaconda-ks.cfg
-rw-------. 1 root root 12450 Oct 17 22:30 .bash_history
-rw-r--r--. 1 root root 18 May 20 2009 .bash_logout
-rw-r--r--. 1 root root 176 May 20 2009 .bash_profile
-rw-r--r--. 1 root root 176 Sep 22 2004 .bashrc
-rw-r--r--. 1 root root 100 Sep 22 2004 .cshrc
-rw-r--r--. 1 root root 41955 Sep 29 04:38 install.log
-rw-r--r--. 1 root root 9154 Sep 29 04:36 install.log.syslog
drwxr-xr-x. 3 root root 4096 Sep 29 23:00 .ivy2
-rw-------. 1 root root 403 Oct 17 02:56 .mysql_history
-rw-------. 1 root root 104 Oct 17 20:38 .mysql_secret
drwx------. 2 root root 4096 Sep 28 23:53 .ssh
-rw-r--r--. 1 root root 129 Dec 3 2004 .tcshrc
-rw-------. 1 root root 0 Sep 29 21:05 .Xauthority
[root@Master ~]# cat .mysql_secret
# The random password set for the root user at Tue Oct 17 20:38:12 2017 (local time):
fVf6JSCCgGqhbl5B
6.3.使用命令mysql -uroot -p登录mysql数据库,输入mysql安装时为root用户随机生成的密码,登录成功。
[root@Master mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1140
Server version: 5.6.38
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>
6.4.使用我们自己设定的密码替代随机密码
1.设定新密码为123456,然后退出登录,重启mysql服务,然后就可以使用新设定的密码登录mysql数据库了
mysql>
SET PASSWoRD FOR 'root'@'localhost'=PASSWoRD('123456');
Query OK, 0 rows affected (0.01 sec)
mysql>
quit
Bye
[root@Master mysql]#
service mysql restart
Shutting down MySQL.. SUCCESS!
Starting MySQL..... SUCCESS!
[root@Master mysql]#
mysql -uroot -p123456
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 5
Server version: 5.6.38 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 databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.01 sec)
mysql>
七、已RPM方式完全卸载mysql数据库
7.1
查看系统中是否有rpm方式安装的mysql
[root@Master ~]#
rpm -qa | grep -i mysql
MySQL-client-5.6.38-1.el6.x86_64
MySQL-shared-5.6.38-1.el6.x86_64
MySQL-server-5.6.38-1.el6.x86_64
MySQL-devel-5.6.38-1.el6.x86_64
7.2卸载mysql,以安装mysql的逆序进行卸载
[root@Master ~]
#
rpm -e
MySQL-devel-5.6.38-1.el6.x86_64
[root@Master ~]
#
rpm -e
MySQL-client-5.6.38-1.el6.x86_64
[root@Master ~]
#
rpm -e
MySQL-server-5.6.38-1.el6.x86_64
[root@Master ~]
#
rpm -e
MySQL-shared-5.6.38-1.el6.x86_64
7.3
清空与mysql相关的所有目录及文件,可以使用命令
find / -name mysql
进行查找
rm -rf
/usr/share/mysql
rm -rf
/usr/my.cnf
至此,根据上述步骤读者可以在redhat linux使用yum方式安装mysql5.6,以及修改mysql的安装路径以及完全卸载mysql了。