useradd MysqL -M -s /bin/nologin && id MysqL
解压二进制包
tar xf MysqL-5.5.xx-linux2.6-x86_64.tar.gz
复制到/application目录下,并改名
mkdir -p /application
mv MysqL-5.5.xx... /aplication/MysqL-xxx
创建软连接去掉版本号
ln -s /application/MysqL-5.5.xx /application/MysqL
初始化数据库(MysqL5.5),授权MysqL用户管理数据库文件
/application/MysqL/scripts/MysqL_install_db \
--basedir=/application/MysqL/ --datadir=/application/MysqL/data/ --user=MysqL &&\
chown -vR MysqL.MysqL /application/MysqL
初始化错误的时候可删除对应的目录,检查权限后重新执行,注意/tmp目录的权限应该为1777
/bin/rm -fr /application/MysqL/data/*
将标准配置文件目录其中一个文件复制到/etc/my.cnf,配置启动脚本
cd /application/MysqL/support-files &&\
/bin/cp /application/MysqL/support-files/my-small.cnf /etc/my.cnf &&\
sed -i 's#/usr/local/MysqL#/application/MysqL#g' /application/MysqL/bin/MysqLd_safe
/application/MysqL/bin/MysqLd_safe &
lsof -i :3306
配置命令路径到$PATH
cat >> /etc/profile <<eof
MysqL_HOME="/application/MysqL"
PATH="\${MysqL_HOME}/bin:\${PATH}"
eof
. /etc/profile
复制并修改启动脚本到/etc/init.d/里进行开机自启动管理(chkconfig管理方式)
cp /application/MysqL/support-files/MysqL.server /etc/init.d/MysqLd &&\
sed -i 's#/usr/local/MysqL#/application/MysqL#g' /etc/init.d/MysqLd &&\
chkconfig MysqLd on &&\
chkconfig --list MysqLd
退出MysqL后设置MysqL的root密码,重新登陆就需要密码了
MysqLadmin -uroot password "11111111" &&\
MysqL -uroot -p
MysqLadmin -uroot -p11111111 password "newpassword"
MysqL基本语句
show databases; 查看库
select user(); 查看当前用户
use MysqL; 使用某个库
select database(); 查看当前库
drop database test; 删库
show tables; 查看表
select user,host from MysqL.user; 查看系统用户,两个字段确定一个用户
drop user ''@'localhost';flush privileges; 删用户,部分用户名为空,用‘’
delete from MysqL.user where user='root' and host = 'localhost';flush privileges; 在表里删用户
grant all on *.* to '123'@'localhost' identified by '11111111' with grant option;flush privileges; 创建用户
help 帮助
quit 退出