感谢分享:http://blog.csdn.net/zq9017197/article/details/49871973
- MysqL的安装分为三种:1、RPM包安装;2、二进制包安装;3、源码安装。
- 第一种方式比较简单,直接RPM包安装就OK了,或者通过yum源来安装,而第三种方式比较复杂。
- 一般项目中使用比较多的是通过二进制包来安装,这种安装方式可以根据企业的不同需求进行相关的自定义配置,比如安装在哪个目录,如何配置等。
- 现在具体介绍一下MysqL的二进制安装方式
- 1:查看系统版本
- [root@CentOS~]#cat/etc/redhat-release
- CentOSrelease6.5(Final)
- 2:添加用户和组
- [root@CentOSMysqL]#groupaddMysqL
- [root@CentOSMysqL]#useradd-r-gMysqLMysqL
- 3:安装MysqL到/usr/local/MysqL下
- [root@CentOS~]#cd/tmp
- [root@CentOStmp]#llMysqL-5.6.27-linux-glibc2.5-i686.tar.gz
- -rw-r--r--.1rootroot30405622611月1704:12MysqL-5.6.27-linux-glibc2.5-i686.tar.gz
- [root@CentOStmp]#tarzxfMysqL-5.6.27-linux-glibc2.5-i686.tar.gz-C/usr/local/
- [root@CentOStmp]#cd/usr/local/
- [root@CentOSlocal]#mvMysqL-5.6.27-linux-glibc2.5-i686/MysqL
- [root@CentOSlocal]#chown-RMysqL:MysqLMysqL/
- [root@CentOSMysqL]#mkdir/mydata
- [root@CentOSMysqL]#chown-RMysqL:MysqL/mydata
- 4:初始化MysqL
- [root@CentOS/]#cd/usr/local/MysqL
- [root@CentOSMysqL]#./scripts/MysqL_install_db--user=MysqL--basedir=/usr/local/MysqL--datadir=/mydata
- [root@CentOSMysqL]#chown-RMysqL:MysqL*
- 5:修改MysqL主配置文件
- [root@CentOSMysqL]#cd/usr/local/MysqL
- [root@CentOSMysqL]#cpsupport-files/my-default.cnf/etc/my.cnf##注:如果/etc/my.cnf文件存在,则覆盖。
- [root@CentOSMysqL]#vi/etc/my.cnf
- [client]
- password=123456
- port=3306
- default-character-set=utf8
- [MysqLd]
- datadir=/mydata
- port=3306
- character_set_server=utf8
- character_set_client=utf8
- collation-server=utf8_general_ci
- lower_case_table_names=1
- max_connections=1000
- [MysqL]
- 6:为MysqL提供服务脚本
- [root@CentOSMysqL]#cd/usr/local/MysqL
- [root@CentOSMysqL]#cpsupport-files/MysqL.server/etc/rc.d/init.d/MysqLd
- 7:添加开启自启
- [root@CentOSinit.d]#chkconfig--addMysqLd
- [root@CentOSinit.d]#chkconfigMysqLdon
- 8:启动MysqL
- [root@CentOSinit.d]#serviceMysqLdstart
- StartingMysqL...[确定]
- [root@CentOSinit.d]#serviceMysqLdstatus
- MysqLrunning(2068)[确定]
- 9:添加环境变量
- [root@CentOSbin]#vi/etc/profile
- PATH=/usr/local/MysqL/bin:/usr/local/MysqL/lib:$PATH
- exportPATH
- 或
- [root@CentOSinit.d]#ln-s/usr/local/MysqL/bin/MysqL/usr/bin
- 10:登录MysqL,修改密码,删除空用户(密码为空)
- [root@CentOSinit.d]#MysqL-uroot-p-S/tmp/MysqL.sock
- MysqL>selectuser,host,passwordfromMysqL.user;
- +------+-----------+----------+
- |user|host|password|
- |root|localhost||
- |root|centos||
- |root|127.0.0.1||
- |root|::1||
- ||localhost||
- ||centos||
- +------+-----------+----------+
- 6rowsinset(0.00sec)
- MysqL>updateMysqL.usersetpassword=PASSWORD('123456')whereuser='root';
- +------+-----------+-------------------------------------------+
- |root|localhost|*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9|
- |root|centos|*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9|
- |root|127.0.0.1|*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9|
- |root|::1|*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9|
- +------+-----------+-------------------------------------------+
- MysqL>dropuser''@localhost;
- ||centos||
- MysqL>useMysqL
- MysqL>updateusersethost='%'whereuser='root'andhost='localhost';
- QueryOK,1rowaffected(0.00sec)
- Rowsmatched:1Changed:1Warnings:0
- |root|%|*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9|
- 5rowsinset(0.00sec)
- MysqL>FLUSHPRIVILEGES;
- 参考:
- http://blog.csdn.net/cnyyx/article/details/45151693
- //www.cnblogs.com/xiaoit/p/3988640.html