思路:
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
|
本文详细介绍如何在Linux环境下安装MySQL,并提供了启动、配置、登录及远程访问的方法。此外,还介绍了重要目录的位置、卸载步骤及常见错误处理。
586

被折叠的 条评论
为什么被折叠?



