1.查看数据库中已安装的版本:
[mdata@bogon ~]$ yum list installed|grep mysql
mysql-libs.x86_64 5.1.71-1.el6 @anaconda-CentOS-201311272149.x86_64/6.5
2.移除数据库中已有的版本:
[root@bogon mdata]# yum -y remove mysql-libs.x86_64
...
Complete!
3.下载mysql数据库安装包:
[root@bogon mdata]# wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
--2018-04-12 03:07:43-- http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
Resolving repo.mysql.com... 23.55.208.125
Connecting to repo.mysql.com|23.55.208.125|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5824 (5.7K) [application/x-redhat-package-manager]
Saving to: “mysql-community-release-el6-5.noarch.rpm”
100%[======================================>] 5,824 11.7K/s in 0.5s
2018-04-12 03:07:43 (11.7 KB/s) - “mysql-community-release-el6-5.noarch.rpm” saved [5824/5824]
4.解压压缩包:
[root@bogon mdata]# rpm -ivh mysql-community-release-el6-5.noarch.rpm
Preparing... ########################################### [100%]
1:mysql-community-release########################################### [100%]
5.查看解压结果:
[root@bogon mdata]# yum repolist all|grep mysql
mysql-connectors-community MySQL Connectors Community enabled: 45
mysql-connectors-community-source MySQL Connectors Community - So disabled
mysql-tools-community MySQL Tools Community enabled: 57
mysql-tools-community-source MySQL Tools Community - Source disabled
mysql55-community MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - So disabled
mysql56-community MySQL 5.6 Community Server enabled: 415
mysql56-community-source MySQL 5.6 Community Server - So disabled
mysql57-community-dmr MySQL 5.7 Community Server Deve disabled
mysql57-community-dmr-source MySQL 5.7 Community Server Deve disabled
6.安装mysql数据库:
[root@bogon mdata]# yum install mysql-community-server -y
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirror.bit.edu.cn
* updates: mirror.bit.edu.cn
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.6.39-2.el6 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.6.39-2.el6 for package: mysql-community-server-5.6.39-2.el6.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.6.10 for package: mysql-community-server-5.6.39-2.el6.x86_64
--> Processing Dependency: perl(DBI) for package: mysql-community-server-5.6.39-2.el6.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.6.39-2.el6 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.6.10 for package: mysql-community-client-5.6.39-2.el6.x86_64
---> Package mysql-community-common.x86_64 0:5.6.39-2.el6 will be installed
---> Package perl-DBI.x86_64 0:1.609-4.el6 will be installed
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:5.6.39-2.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
mysql-community-server x86_64 5.6.39-2.el6 mysql56-community 55 M
Installing for dependencies:
mysql-community-client x86_64 5.6.39-2.el6 mysql56-community 18 M
mysql-community-common x86_64 5.6.39-2.el6 mysql56-community 308 k
mysql-community-libs x86_64 5.6.39-2.el6 mysql56-community 1.9 M
perl-DBI x86_64 1.609-4.el6 base 705 k
Transaction Summary
================================================================================
Install 5 Package(s)
Total download size: 75 M
Installed size: 337 M
Downloading Packages:
(1/5): mysql-community-client-5.6.39-2.el6.x86_64.rpm | 18 MB 13:18
(2/5): mysql-community-common-5.6.39-2.el6.x86_64.rpm | 308 kB 00:15
(3/5): mysql-community-libs-5.6.39-2.el6.x86_64.rpm | 1.9 MB 01:19
(4/5): mysql-community-server-5.6.39-2.el6.x86_64.rpm | 55 MB 42:12
(5/5): perl-DBI-1.609-4.el6.x86_64.rpm | 705 kB 00:01
--------------------------------------------------------------------------------
Total 22 kB/s | 75 MB 57:08
warning: rpmts_HdrFromFdno: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Retrieving key from file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
Userid : MySQL Release Engineering
Package: mysql-community-release-el6-5.noarch (installed)
From : file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Importing GPG key 0xC105B9DE:
Userid : CentOS-6 Key (CentOS 6 Official Signing Key)
Package: centos-release-6-5.el6.centos.11.1.x86_64 (@anaconda-CentOS-201311272149.x86_64/6.5)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
Installing : mysql-community-common-5.6.39-2.el6.x86_64 1/5
Installing : mysql-community-libs-5.6.39-2.el6.x86_64 2/5
Installing : mysql-community-client-5.6.39-2.el6.x86_64 3/5
Installing : perl-DBI-1.609-4.el6.x86_64 4/5
Installing : mysql-community-server-5.6.39-2.el6.x86_64 5/5
Verifying : mysql-community-server-5.6.39-2.el6.x86_64 1/5
Verifying : mysql-community-libs-5.6.39-2.el6.x86_64 2/5
Verifying : mysql-community-client-5.6.39-2.el6.x86_64 3/5
Verifying : mysql-community-common-5.6.39-2.el6.x86_64 4/5
Verifying : perl-DBI-1.609-4.el6.x86_64 5/5
Installed:
mysql-community-server.x86_64 0:5.6.39-2.el6
Dependency Installed:
mysql-community-client.x86_64 0:5.6.39-2.el6
mysql-community-common.x86_64 0:5.6.39-2.el6
mysql-community-libs.x86_64 0:5.6.39-2.el6
perl-DBI.x86_64 0:1.609-4.el6
Complete!
7.查看已安装的数据库版本:
[root@bogon mdata]# yum list installed|grep mysql
mysql-community-client.x86_64
5.6.39-2.el6 @mysql56-community
mysql-community-common.x86_64
5.6.39-2.el6 @mysql56-community
mysql-community-libs.x86_64
5.6.39-2.el6 @mysql56-community
mysql-community-release.noarch
mysql-community-server.x86_64
5.6.39-2.el6 @mysql56-community
8.添加开机启动项:
[root@bogon mdata]# chkconfig --list|grep mysqld
mysqld 0:off1:off2:off3:on4:on5:on6:off
[root@bogon mdata]# chkconfig mysql on
error reading information on service mysql: No such file or directory
[root@bogon mdata]# chkconfig mysqld on
9.启动mysql服务器:
[root@bogon mdata]# service mysqld start
Initializing MySQL database: 2018-04-12 05:38:48 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-04-12 05:38:48 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-04-12 05:38:48 0 [Note] /usr/sbin/mysqld (mysqld 5.6.39) starting as process 18488 ...
2018-04-12 05:38:48 18488 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-04-12 05:38:48 18488 [Note] InnoDB: The InnoDB memory heap is disabled
2018-04-12 05:38:48 18488 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-04-12 05:38:48 18488 [Note] InnoDB: Memory barrier is not used
2018-04-12 05:38:48 18488 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-04-12 05:38:48 18488 [Note] InnoDB: Using Linux native AIO
2018-04-12 05:38:48 18488 [Note] InnoDB: Using CPU crc32 instructions
2018-04-12 05:38:48 18488 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-04-12 05:38:48 18488 [Note] InnoDB: Completed initialization of buffer pool
2018-04-12 05:38:48 18488 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2018-04-12 05:38:48 18488 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2018-04-12 05:38:48 18488 [Note] InnoDB: Database physically writes the file full: wait...
2018-04-12 05:38:48 18488 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2018-04-12 05:38:48 18488 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2018-04-12 05:38:49 18488 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2018-04-12 05:38:49 18488 [Warning] InnoDB: New log files created, LSN=45781
2018-04-12 05:38:49 18488 [Note] InnoDB: Doublewrite buffer not found: creating new
2018-04-12 05:38:49 18488 [Note] InnoDB: Doublewrite buffer created
2018-04-12 05:38:49 18488 [Note] InnoDB: 128 rollback segment(s) are active.
2018-04-12 05:38:49 18488 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-04-12 05:38:49 18488 [Note] InnoDB: Foreign key constraint system tables created
2018-04-12 05:38:49 18488 [Note] InnoDB: Creating tablespace and datafile system tables.
2018-04-12 05:38:49 18488 [Note] InnoDB: Tablespace and datafile system tables created.
2018-04-12 05:38:49 18488 [Note] InnoDB: Waiting for purge to start
2018-04-12 05:38:49 18488 [Note] InnoDB: 5.6.39 started; log sequence number 0
2018-04-12 05:38:49 18488 [Note] Binlog end
2018-04-12 05:38:49 18488 [Note] InnoDB: FTS optimize thread exiting.
2018-04-12 05:38:49 18488 [Note] InnoDB: Starting shutdown...
2018-04-12 05:38:51 18488 [Note] InnoDB: Shutdown completed; log sequence number 1625977
2018-04-12 05:38:51 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-04-12 05:38:51 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-04-12 05:38:51 0 [Note] /usr/sbin/mysqld (mysqld 5.6.39) starting as process 18510 ...
2018-04-12 05:38:51 18510 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-04-12 05:38:51 18510 [Note] InnoDB: The InnoDB memory heap is disabled
2018-04-12 05:38:51 18510 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-04-12 05:38:51 18510 [Note] InnoDB: Memory barrier is not used
2018-04-12 05:38:51 18510 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-04-12 05:38:51 18510 [Note] InnoDB: Using Linux native AIO
2018-04-12 05:38:51 18510 [Note] InnoDB: Using CPU crc32 instructions
2018-04-12 05:38:51 18510 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-04-12 05:38:51 18510 [Note] InnoDB: Completed initialization of buffer pool
2018-04-12 05:38:51 18510 [Note] InnoDB: Highest supported file format is Barracuda.
2018-04-12 05:38:51 18510 [Note] InnoDB: 128 rollback segment(s) are active.
2018-04-12 05:38:51 18510 [Note] InnoDB: Waiting for purge to start
2018-04-12 05:38:51 18510 [Note] InnoDB: 5.6.39 started; log sequence number 1625977
2018-04-12 05:38:51 18510 [Note] Binlog end
2018-04-12 05:38:51 18510 [Note] InnoDB: FTS optimize thread exiting.
2018-04-12 05:38:51 18510 [Note] InnoDB: Starting shutdown...
2018-04-12 05:38:53 18510 [Note] InnoDB: Shutdown completed; log sequence number 1625987
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h bogon password 'new-password'
Alternatively you can run:
/usr/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.
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
Note: new default config file not created.
Please make sure your config file is current
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
[ OK ]
Starting mysqld: [ OK ]
10.mysql数据库安全设置(密码设置):
[root@bogon mdata]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] n
... skipping.
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
... Failed! Not critical, keep moving...
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Cleaning up...
11.授权远程登录:
[root@bogon mdata]# mysql -uroot -p密码
mysql> grant all privileges on *.* to 'root'@'%' identified by 'mdata2018' with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
12.关闭防火墙:
service iptables stop