点击打开链接
思路:
1、查看有无安装过MysqL
|
1
|
rpm -qa|grep MysqL
|
或
|
1
|
yum list installed MysqL
|
2、查看有无安装包
|
1
|
yum list MysqL*
|
3、安装MysqL服务端
|
1
2
|
yum install MysqL-server
yum install MysqL-devel
|
4、启动&&停止
a、设置数据库默认字符
在MysqL配置文件/etc/my.cnf中加入default-character-set=utf8
|
1
|
vim /etc/my.cnf
|
b、设置开机自启动
|
1
2
|
chkconfig MysqLd
on
chkconfig --list MysqLd
|
c、启动MysqL
|
1
|
service MysqLd start
|
5、登录
a、创建root管理员
|
1
|
MysqLadmin -u root password 123456
|
b、忘记密码
|
1
2
3
4
5
6
|
service MysqLd stop
MysqLd_safe --user=root --skip-grant-tables
MysqL -u root
use MysqL
update user
set
password=password(
"new_pass"
)
where
user=
"root"
;
flush privileges;
|
6、远程访问
a、修改localhost
更改 "MysqL" 数据库里的 "user" 表里的 "host" 项,从"localhost"改成"%"
|
1
2
3
4
|
MysqL>use MysqL;
MysqL>update user
set
host =
'%'
where
user =
'root'
;
MysqL>
select
host,user
from
user;
MysqL>FLUSH PRIVILEGES;
|
b、指定授权
1、使用myuser/mypassword从任何主机连接到MysqL服务器:
|
1
|
GRANT ALL PRIVILEGES ON *.* TO
'myuser'
@
'%'
IDENTIFIED BY
'mypassword'
WITH GRANT OPTION;
|
2、使用myuser/mypassword从ip为192.168.225.166的主机连接到MysqL服务器:
|
1
|
GRANT ALL PRIVILEGES ON *.* TO
'myuser'
@
'192.168.1.166'
IDENTIFIED BY
'mypassword'
WITH GRANT OPTION;
|
3、泛授权
|
1
2
3
|
MysqL -h localhost -u root
MysqL>GRANT ALL PRIVILEGES ON *.* TO
'root'
@
'%'
WITH GRANT OPTION;
//赋予任何主机上以root身份访问数据的权限
MysqL>FLUSH PRIVILEGES;
|
7、MysqL的几个重要目录
a、数据库目录
|
1
|
/
var
/lib/MysqL/
|
b、配置文件
|
1
|
/usr/share /MysqL(MysqL.server命令及配置文件)
|
c、相关命令
|
1
|
/usr/bin(MysqLadmin MysqLdump等命令)
|
d、启动脚本
|
1
|
/etc/rc.d/init.d/(启动脚本文件MysqL的目录)
|
8、卸载MysqL
a、查找以前是否装有MysqL
|
1
|
rpm -qa|grep -i MysqL
|
b、删除MysqL
|
1
2
3
|
1、yum remove MysqL MysqL-server MysqL-libs compat-MysqL51
2、rm -rf /
var
/lib/MysqL
3、rm /etc/my.cnf
|
9、bug处理
a、ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
解决方法:
1、停止MysqL服务器
|
1
|
service MysqLd stop
|
2、使用MysqLd_safe命令在启动MysqL,更新root账号的密码
|
1
|
MysqLd_safe --user=MysqL --skip-grant-tables --skip-networking &:
|
注:--skip-grant-tables:不启动grant-tables(授权表),跳过权限控制。
--skip-networking :跳过TCP/IP协议,只在本机访问(从网上有些资料看,这个选项不是必须的。可以不用)
执行上面命令后,此会话窗口会出现无反应的状态,需要使用CTRL+C中断会话
3、设置密码
|
1
2
3
4
|
MysqL -u root MysqL
MysqL> update user
set
password=PASSWORD(
'12345'
)
->
where
user=
'root'
and host=
'root'
or host=
'localhost'
;
flush privileges
|
4、启动MysqL服务
|
1
|
service MysqLd start
|