-。安装并配置myql

1.1执行yum命令安装MySQL

yum-yinstallmysqlmysql-server

1.2把添加MySQL进开机启动项,并立即启动MySQL

chkconfig--levels235mysqldon

/etc/init.d/mysqldstart

1.3设置MySQLroot帐号密码

/usr/bin/mysql_secure_installation

NOTE:RUNNINGALLPARTSOFTHISSCRIPTISRECOMMENDEDFORALLMySQLSERVERSINPRODUCTIONUSE!PLEASEREADEACHSTEPCAREFULLY!

InordertologintoMySQLtosecureit,we'llneedthecurrent

passwordfortherootuser.Ifyou'vejustinstalledMySQL,and

youhaven'tsettherootpasswordyet,thepasswordwillbeblank,

soyoushouldjustpressenterhere.

Entercurrentpasswordforroot(enterfornone):<--输入系统root密码

OK,successfullyusedpassword,movingon...

SettingtherootpasswordensuresthatnobodycanlogintotheMySQL

rootuserwithouttheproperauthorisation.

Setrootpassword?[Y/n]<--ENTER

Newpassword:<--你的MySQLroot密码

Re-enternewpassword:<--你的MySQLroot密码

Passwordupdatedsuccessfully!

Reloadingprivilegetables..

...Success!

Bydefault,aMySQLinstallationhasananonymoususer,allowinganyone

tologintoMySQLwithouthavingtohaveauseraccountcreatedfor

  1. Thisisintendedonlyfortesting,andtomaketheinstallation

goabitsmoother.Youshouldremovethembeforemovingintoa

productionenvironment.

Removeanonymoususers?[Y/n]<--ENTER

...Success!

Normally,rootshouldonlybeallowedtoconnectfrom'localhost'.This

ensuresthatsomeonecannotguessattherootpasswordfromthenetwork.

Disallowrootloginremotely?[Y/n]<--ENTER

...Success!

Bydefault,MySQLcomeswithadatabasenamed'test'thatanyonecan

  1. Thisisalsointendedonlyfortesting,andshouldberemoved

beforemovingintoaproductionenvironment.

Removetestdatabaseandaccesstoit?[Y/n]<--ENTER

-Droppingtestdatabase...

...Success!

-Removingprivilegesontestdatabase...

...Success!

Reloadingtheprivilegetableswillensurethatallchangesmadesofar

willtakeeffectimmediately.

Reloadprivilegetablesnow?[Y/n]<--ENTER

...Success!

Cleaningup...

Alldone!Ifyou'vecompletedalloftheabovesteps,yourMySQL

installationshouldnowbesecure.

ThanksforusingMySQL!

修改yum安装mysql的路径

>1、
使用命令servicemysqldstop停止mysql
查看mysql数据库的默认路径:/var/lib/mysql
使用cp-afir/var/lib/mysql/*/usr/local/mysql
这里的afir参数具体指什么请查看cp的帮助
2、
更改my.cnf
使用命令:vim/etc/my.cnf
把其中的datadir更改为新的路径
datadir=/usr/local/mysql
为保证MySQL能够正常,需要指明mysql.sock文件的产生位置。
#socket =/var/lib/mysql/mysql.sock(原内容,为了更稳妥用“#”注释此行)
socket =/usr/local/mysql/mysql.sock (加上此行)
3、修改MySQL启动脚本/etc/init.d/mysqld,

找到 get_mysql_optionmysqlddatadir"/var/lib/mysql/mysql"一行改成你现在的实际存放路径/usr/local/mysql

5、ln-s/usr/local/mysql/mysql.sock/var/lib/mysql/mysql.sock
给mysql.sock建立一个软链接,否则会提示找不到/var/lib/mysql/mysql.sock
6、重启mysqld
servicemysqldrestart