a.检查下linux是不是已经安装了mysql
[root@CentOS ~]# rpm -qa | grep -i mysql #grep -i是不分大小写字符查询,只要含有mysql就显示
mysql-libs-5.1.71-1.el6.i686 #如果安装了先卸载旧的版本
[root@CentOS ~]# yum -y remove mysql-libs
[root@CentOS ~]# rpm -qa | grep -i mysql
屏幕显示:
mysql-libs-5.1.71-1.el6.i686 //它是好几个软件的依赖,其中在mini版本中postfix软件依赖mysql-libs,网络上很多建议都是直接删除,
yum remove mysql-libs 或者 rpm -e --nodeps mysql-libs-5.1.71-1.el6.i686,总觉得这样做不好。
查找mysql官方资料,得到安装方法是用MySQL-shared-compat将mysql-libs-5.1.71-1.el6.i686替换为同版本后在安装mysql。
b.创建需要下载rpm软件包的目录
[root@CentOS ~]# cd /
[root@CentOS /]# mkdir tools
[root@CentOS /]# cd tools/
[root@CentOS tools]# tar xf MySQL-5.6.27-1.linux_glibc2.5.i386.rpm-bundle.tar
[root@CentOS tools]# ll
总用量 607688
-rw-r--r--. 1 root root 311132160 11月 15 20:51 MySQL-5.6.27-1.linux_glibc2.5.i386.rpm-bundle.tar
-rw-r--r--. 1 7155 wheel 22940013 9月 22 00:32 MySQL-client-5.6.27-1.linux_glibc2.5.i386.rpm
-rw-r--r--. 1 7155 wheel 4193230 9月 22 00:32 MySQL-devel-5.6.27-1.linux_glibc2.5.i386.rpm
-rw-r--r--. 1 7155 wheel 113074786 9月 22 00:32 MySQL-embedded-5.6.27-1.linux_glibc2.5.i386.rpm
-rw-r--r--. 1 7155 wheel 88299856 9月 22 00:33 MySQL-server-5.6.27-1.linux_glibc2.5.i386.rpm
-rw-r--r--. 1 7155 wheel 2372993 9月 22 00:33 MySQL-shared-5.6.27-1.linux_glibc2.5.i386.rpm
-rw-r--r--. 1 7155 wheel 5368256 9月 22 00:33 MySQL-shared-compat-5.6.27-1.linux_glibc2.5.i386.rpm
-rw-r--r--. 1 7155 wheel 74877142 9月 22 00:34 MySQL-test-5.6.27-1.linux_glibc2.5.i386.rpm
c.开始逐个安装
[root@CentOS tools]# rpm -ivh MySQL-server-5.6.27-1.linux_glibc2.5.i386.rpm
warning: MySQL-server-5.6.27-1.linux_glibc2.5.i386.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:MySQL-server ########################################### [100%]
warning: user mysql does not exist - using root
warning: group mysql does not exist - using root
2015-11-15 20:52:37 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-11-15 20:52:37 0 [Note] /usr/sbin/mysqld (mysqld 5.6.27) starting as process 1747 ...
2015-11-15 20:52:37 1747 [Note] InnoDB: Using mutexes to ref count buffer pool pages
2015-11-15 20:52:37 1747 [Note] InnoDB: The InnoDB memory heap is disabled
2015-11-15 20:52:37 1747 [Note] InnoDB: Mutexes and rw_locks use InnoDB's own implementation
2015-11-15 20:52:37 1747 [Note] InnoDB: Memory barrier is not used
2015-11-15 20:52:37 1747 [Note] InnoDB: Compressed tables use zlib 1.2.3
2015-11-15 20:52:37 1747 [Note] InnoDB: Using Linux native AIO
2015-11-15 20:52:37 1747 [Note] InnoDB: Not using CPU crc32 instructions
2015-11-15 20:52:37 1747 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-11-15 20:52:37 1747 [Note] InnoDB: Completed initialization of buffer pool
2015-11-15 20:52:37 1747 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2015-11-15 20:52:37 1747 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2015-11-15 20:52:37 1747 [Note] InnoDB: Database physically writes the file full: wait...
2015-11-15 20:52:37 1747 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2015-11-15 20:52:38 1747 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2015-11-15 20:52:38 1747 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2015-11-15 20:52:38 1747 [Warning] InnoDB: New log files created, LSN=45781
2015-11-15 20:52:38 1747 [Note] InnoDB: Doublewrite buffer not found: creating new
2015-11-15 20:52:38 1747 [Note] InnoDB: Doublewrite buffer created
2015-11-15 20:52:38 1747 [Note] InnoDB: 128 rollback segment(s) are active.
2015-11-15 20:52:38 1747 [Warning] InnoDB: Creating foreign key constraint system tables.
2015-11-15 20:52:39 1747 [Note] InnoDB: Foreign key constraint system tables created
2015-11-15 20:52:39 1747 [Note] InnoDB: Creating tablespace and datafile system tables.
2015-11-15 20:52:39 1747 [Note] InnoDB: Tablespace and datafile system tables created.
2015-11-15 20:52:39 1747 [Note] InnoDB: Waiting for purge to start
2015-11-15 20:52:39 1747 [Note] InnoDB: 5.6.27 started; log sequence number 0
A random root password has been set. You will find it in '/root/.mysql_secret'.
2015-11-15 20:52:39 1747 [Note] Binlog end
2015-11-15 20:52:39 1747 [Note] InnoDB: FTS optimize thread exiting.
2015-11-15 20:52:39 1747 [Note] InnoDB: Starting shutdown...
2015-11-15 20:52:41 1747 [Note] InnoDB: Shutdown completed; log sequence number 1625977
2015-11-15 20:52:41 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-11-15 20:52:41 0 [Note] /usr/sbin/mysqld (mysqld 5.6.27) starting as process 1769 ...
2015-11-15 20:52:41 1769 [Note] InnoDB: Using mutexes to ref count buffer pool pages
2015-11-15 20:52:41 1769 [Note] InnoDB: The InnoDB memory heap is disabled
2015-11-15 20:52:41 1769 [Note] InnoDB: Mutexes and rw_locks use InnoDB's own implementation
2015-11-15 20:52:41 1769 [Note] InnoDB: Memory barrier is not used
2015-11-15 20:52:41 1769 [Note] InnoDB: Compressed tables use zlib 1.2.3
2015-11-15 20:52:41 1769 [Note] InnoDB: Using Linux native AIO
2015-11-15 20:52:41 1769 [Note] InnoDB: Not using CPU crc32 instructions
2015-11-15 20:52:41 1769 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-11-15 20:52:41 1769 [Note] InnoDB: Completed initialization of buffer pool
2015-11-15 20:52:41 1769 [Note] InnoDB: Highest supported file format is Barracuda.
2015-11-15 20:52:41 1769 [Note] InnoDB: 128 rollback segment(s) are active.
2015-11-15 20:52:41 1769 [Note] InnoDB: Waiting for purge to start
2015-11-15 20:52:41 1769 [Note] InnoDB: 5.6.27 started; log sequence number 1625977
2015-11-15 20:52:41 1769 [Note] Binlog end
2015-11-15 20:52:41 1769 [Note] InnoDB: FTS optimize thread exiting.
2015-11-15 20:52:41 1769 [Note] InnoDB: Starting shutdown...
2015-11-15 20:52:43 1769 [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'. ##为MySQL的数据库的root的用户生成了一个随机的秘密,请到/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
[root@CentOS tools]# rpm -ivh MySQL-devel-5.6.27-1.linux_glibc2.5.i386.rpm
warning: MySQL-devel-5.6.27-1.linux_glibc2.5.i386.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:MySQL-devel ########################################### [100%]
[root@CentOS tools]# rpm -ivh MySQL-client-5.6.27-1.linux_glibc2.5.i386.rpm
warning: MySQL-client-5.6.27-1.linux_glibc2.5.i386.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:MySQL-client ########################################### [100%]
[root@CentOS tools]# cat /root/.mysql_secret
# The random password set for the root user at Sun Nov 15 20:52:39 2015 (local time): 2_uvu1WCGxRqcF4d
d.修改配置文件位置并做相关设置
1.数据库目录 /var/lib/mysql/
2、配置文件 /usr/share/mysql(mysql.server命令及配置文件)
3、相关命令 /usr/bin(mysqladmin mysqldump等命令)
4、启动脚本 /etc/rc.d/init.d/(启动脚本文件mysql的目录)
注意:mysql-5.6 下 /usr/share/mysql/下有好几个结尾为cnf的文件,它们的作用分别是:
[root@CentOS etc]# cd /usr/share/mysql/
[root@CentOS mysql]# ll *.cnf
-rwxr-xr-x. 1 root root 4697 9月 18 23:17 my-huge.cnf
-rwxr-xr-x. 1 root root 19779 9月 18 23:17 my-innodb-heavy-4G.cnf
-rwxr-xr-x. 1 root root 4671 9月 18 23:17 my-large.cnf
-rwxr-xr-x. 1 root root 4682 9月 18 23:17 my-medium.cnf
-rwxr-xr-x. 1 root root 2846 9月 18 23:17 my-small.cnf
1.my-small.cnf是为了小型数据库而设计的。不应该把这个模型用于含有一些常用项目的数据库。
2.my-medium.cnf是为中等规模的数据库而设计的。如果你正在企业中使用RHEL,可能会比这个操作系统的最小RAM需求(256MB)明显多得多的物理内存。由此可见,如果有那么多RAM内存可以使用,自然可以在同一台机器上运行其它服务。
3·my-large.cnf是为专用于一个SQL数据库的计算机而设计的。由于它可以为该数据库使用多达512MB的内存,所以在这种类型的系统上将需要至少1GB的RAM,以便它能够同时处理操作系统与数据库应用程序。
4·my-huge.cnf是为企业中的数据库而设计的。这样的数据库要求专用服务器和1GB或1GB以上的RAM。这些选择高度依赖于内存的数量、计算机的运算速度、数据库的细节大小、访问数据库的用户数量以及在数据库中装入并访问数据的用户数量。随着数据库和用户的不断增加,数据库的性能可能会发生变化。
#mysql 5.6 就是/usr/share/mysql/my-default.cnf配置模版:cp /usr/share/mysql/my-default.cnf /etc/my.cnf
[root@CentOS init.d]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
[root@CentOS mysql]# vi /etc/my.cnf
#做如下配置
[client]
password = 123456
port = 3306
default-character-set=utf8
[mysqld]
port = 3306
character_set_server=utf8
character_set_client=utf8
collation-server=utf8_general_ci
lower_case_table_names=1 #linux下mysql安装完后是默认:表名区分大小写,列名不区分大小写; 0:区分大小写,1:不区分大小写
max_connections=1000 #设置最大连接数,默认为151,MySQL服务器允许的最大连接数16384
[mysql]
default-character-set=utf8
#注意要把这行注释掉
#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
e.初始化MySQL及设置密码
[root@CentOS /]# /usr/bin/mysql_install_db
[root@CentOS /]# service mysql start
重启mysql会抛出上面红色字体的错误。上面只能看到mysql启动失败,具体的原因,需要查看数据库目录下的.err文件,查看.err文件,内容如下:
140726 00:18:10 mysqld_safe mysqld from pid file /data/mysql/AY14020816093477605eZ.pid ended
140726 00:31:19 mysqld_safe Starting mysqld daemon with databases from /data/mysql
/usr/local/mysql/bin/mysqld: File ‘./mysql-bin.index' not found (Errcode: 13)
140726 0:31:19 [ERROR] Aborting
140726 0:31:19 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete
红色字标出来的就是这次错误报告,errcode13,一般就是权限问题,mysql用户是否对数据库目录内的所有文件具有写的权限,查看一下权限,修改MySQL目录的用户和用户组权限:
[root@CentOS lib]# chown -R mysql:mysql /var/lib/mysql
f.登录到mysql,第一次装没有密码,直接回车
[root@CentOS mysql]# cat /root/.mysql_secret
# The random password set for the root user at Sun Nov 15 20:52:39 2015 (local time): 2_uvu1WCGxRqcF4d
[root@localhost ~]# mysql -uroot -p2_uvu1WCGxRqcF4d
mysql> SET PASSWORD = PASSWORD('root');
mysql> use mysql
mysql> update user set password=password('root') where user='root';
g.设置允许远程登录
mysql> use mysql;
mysql> select host,user,password from user;
mysql> update user set host='%' where user='root' and host='localhost';
mysql> flush privileges; ##刷新权限表
mysql> exit;
#查看字符集
mysql> show variables like '%collation%';
mysql> show variables like '%char%';
h.设置开机自启动
[root@CentOS mysql]# chkconfig --list mysql
mysql 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
[root@CentOS mysql]# chkconfig mysql on
[root@CentOS mysql]# chkconfig --list mysql
mysql 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
i. MySQL的默认安装位置说明
/var/lib/mysql/ #数据库目录
/usr/share/mysql #配置文件目录
/usr/bin #相关命令目录
/etc/init.d/mysql #启动脚本
注:卸载mysql的时候,将这些目录下的文件也删掉。
参考:
http://blog.csdn.net/waterxcfg304/article/details/36891759
http://blog.csdn.net/mw08091020/article/details/39234207
http://blog.csdn.net/liumm0000/article/details/18841197
http://www.centoscn.com/mysql/2015/0624/5729.html