创建mysql用户
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
启动mysql,后台运行
/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
mysql修改密码
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 退出
mysql错误日志
/application/mysql/data/mysql_server.err
本文出自 “神奇的海螺” 博客,请务必保留此出处http://bilishell.blog.51cto.com/11756401/1829340
原文地址:http://bilishell.blog.51cto.com/11756401/1829340