当前位置:Gxlcms > mysql > Linux系统上安装MySQL5.6

Linux系统上安装MySQL5.6

时间:2021-07-01 10:21:17 帮助过:148人阅读

安装环境 : 软件 版本 位数 MySQL 5.6.22 32 CentOS 6.4 32 VMware 9.0.1 32 Mysql官方下载地址,可以根据当前系统自动识别适合当前系统版本的mysql版本: http://dev.mysql.com/downloads/mysql/ 官网比较慢,百度云盘包含32位和64位的: http://pan.baidu.

安装环境 :

软件 版本 位数
MySQL 5.6.22 32
CentOS 6.4 32
VMware 9.0.1 32

Mysql官方下载地址,可以根据当前系统自动识别适合当前系统版本的mysql版本:

http://dev.mysql.com/downloads/mysql/

官网比较慢,百度云盘包含32位和64位的:

http://pan.baidu.com/s/1sj6YeJj


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

[root@localhost  ~]# yum remove mysql mysql-server mysql-libs


如果之前安装过,则执行rpm -ev进行删除,删除失败,则是有依赖项,则先删除依赖项

[root@localhost ~]# rpm -ev MySQL-server-5.0.22-0.i386
[root@localhost ~]# rpm -ev MySQL-client-5.0.22-0.i386


清除所有mysql相关文件:

[root@localhost ~]#find / -name mysql
[root@localhost ~]#rm -rf 文件或者文件夹


查看是否有残留文件:

[root@localhost ~]#rpm -qa | grep -i mysql


执行命令卸载MySQL相关的文件

[root@localhost ~]# yum -y remove MySQL*


二,安装MySQL

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

[root@localhost opt]# mkdir mysql
[root@localhost opt]# cp /home/duke147/Desktop/Tools/MySQL-5.6.22-1.linux_glibc2.5.i386.rpm-bundle.tar /opt/mysql/
[root@localhost opt]# cd mysql/
[root@localhost mysql]# ls -a 
.  ..  MySQL-5.6.22-1.linux_glibc2.5.i386.rpm-bundle.tar

2.解压安装包

[root@localhost mysql]# tar xvf MySQL-5.6.22-1.linux_glibc2.5.i386.rpm-bundle.tar
MySQL-test-5.6.22-1.linux_glibc2.5.i386.rpm                   #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服务端程序

3.安装服务端

[root@localhost mysql]# rpm -ivh MySQL-server-5.6.22-1.linux_glibc2.5.i386.rpm
Preparing...                ########################################### [100%]
   1:MySQL-server           ########################################### [100%]
2014-12-18 21:08:42 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2014-12-18 21:08:42 4959 [Note] InnoDB: Using mutexes to ref count buffer pool pages
2014-12-18 21:08:42 4959 [Note] InnoDB: The InnoDB memory heap is disabled
2014-12-18 21:08:42 4959 [Note] InnoDB: Mutexes and rw_locks use InnoDB's own implementation
2014-12-18 21:08:42 4959 [Note] InnoDB: Memory barrier is not used
2014-12-18 21:08:42 4959 [Note] InnoDB: Compressed tables use zlib 1.2.3
2014-12-18 21:08:42 4959 [Note] InnoDB: Using Linux native AIO
2014-12-18 21:08:42 4959 [Note] InnoDB: Not using CPU crc32 instructions
2014-12-18 21:08:42 4959 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2014-12-18 21:08:42 4959 [Note] InnoDB: Completed initialization of buffer pool
2014-12-18 21:08:42 4959 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2014-12-18 21:08:42 4959 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2014-12-18 21:08:42 4959 [Note] InnoDB: Database physically writes the file full: wait...
2014-12-18 21:08:42 4959 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2014-12-18 21:08:43 4959 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2014-12-18 21:08:44 4959 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2014-12-18 21:08:44 4959 [Warning] InnoDB: New log files created, LSN=45781
2014-12-18 21:08:44 4959 [Note] InnoDB: Doublewrite buffer not found: creating new
2014-12-18 21:08:44 4959 [Note] InnoDB: Doublewrite buffer created
2014-12-18 21:08:44 4959 [Note] InnoDB: 128 rollback segment(s) are active.
2014-12-18 21:08:44 4959 [Warning] InnoDB: Creating foreign key constraint system tables.
2014-12-18 21:08:44 4959 [Note] InnoDB: Foreign key constraint system tables created
2014-12-18 21:08:44 4959 [Note] InnoDB: Creating tablespace and datafile system tables.
2014-12-18 21:08:44 4959 [Note] InnoDB: Tablespace and datafile system tables created.
2014-12-18 21:08:44 4959 [Note] InnoDB: Waiting for purge to start
2014-12-18 21:08:44 4959 [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'.
2014-12-18 21:08:45 4959 [Note] Binlog end
2014-12-18 21:08:45 4959 [Note] InnoDB: FTS optimize thread exiting.
2014-12-18 21:08:45 4959 [Note] InnoDB: Starting shutdown...
2014-12-18 21:08:46 4959 [Note] InnoDB: Shutdown completed; log sequence number 1625977

2014-12-18 21:08:46 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2014-12-18 21:08:46 4982 [Note] InnoDB: Using mutexes to ref count buffer pool pages
2014-12-18 21:08:46 4982 [Note] InnoDB: The InnoDB memory heap is disabled
2014-12-18 21:08:46 4982 [Note] InnoDB: Mutexes and rw_locks use InnoDB's own implementation
2014-12-18 21:08:46 4982 [Note] InnoDB: Memory barrier is not used
2014-12-18 21:08:46 4982 [Note] InnoDB: Compressed tables use zlib 1.2.3
2014-12-18 21:08:46 4982 [Note] InnoDB: Using Linux native AIO
2014-12-18 21:08:46 4982 [Note] InnoDB: Not using CPU crc32 instructions
2014-12-18 21:08:46 4982 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2014-12-18 21:08:46 4982 [Note] InnoDB: Completed initialization of buffer pool
2014-12-18 21:08:46 4982 [Note] InnoDB: Highest supported file format is Barracuda.
2014-12-18 21:08:46 4982 [Note] InnoDB: 128 rollback segment(s) are active.
2014-12-18 21:08:46 4982 [Note] InnoDB: Waiting for purge to start
2014-12-18 21:08:46 4982 [Note] InnoDB: 5.6.22 started; log sequence number 1625977
2014-12-18 21:08:46 4982 [Note] Binlog end
2014-12-18 21:08:46 4982 [Note] InnoDB: FTS optimize thread exiting.
2014-12-18 21:08:46 4982 [Note] InnoDB: Starting shutdown...
2014-12-18 21:08:48 4982 [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'.

#你可以找从/root/.mysql_secret中找到root用户的随机密码。

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

4.查看,安装客户端,库文件

[root@localhost mysql]# rpm -qa | grep -i mysql
MySQL-server-5.6.22-1.linux_glibc2.5.i386
[root@localhost mysql]# rpm -ivh MySQL-client-5.6.22-1.linux_glibc2.5.i386.rpm
Preparing...                ########################################### [100%]
   1:MySQL-client           ########################################### [100%]
[root@localhost mysql]# rpm -ivh MySQL-devel-5.6.22-1.linux_glibc2.5.i386.rpm 
Preparing...                ########################################### [100%]
   1:MySQL-devel            ########################################### [100%]


MySQL默认安装路径:

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


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

[root@localhost mysql]# cp /usr/share/mysql/my-default.cnf /etc/my.cnf


#如果使用默认配置,则不需要进行修改

[root@localhost mysql]# vi /etc/my.cnf

6.初始化MySQL

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


7.启动MySQL

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

检测mysql 3306是否安打开

[root@localhost mysql]# netstat -nat
tcp        0      0 :::3306                     :::*                        LISTEN  

8.查看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

9.使用默认密码登陆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 4
Server version: 5.6.22

Copyright (c) 2000, 2014, 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> 

修改默认密码:

mysql> set password = password('123456');
Query OK, 0 rows affected (0.02 sec)
退出mysql

mysql> quit;
Bye

10.添加自启动服务

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

11.配置远程访问

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected (0.01 sec)

刷新权限

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

配置单个IP访问权限,*.* 指 【数据库.表】:

mysql > GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.56' IDENTIFIED BY '123456' WITH GRANT OPTION;flush privileges;

关闭防火墙

[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.


修改密码

mysql> use mysql;
mysql> update user set password=password('123456') where user='root';
mysql> flush privileges;

查看数据库

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






人气教程排行