Linux系统下MySQL重要目录和密码管理

2026-02-19 00:50 栏目: 行业动态 查看( )

linux操作系统与MySQL数据库结合搭建的平台为应用程序的开发提供了保障。一个好的开发者在选择开发环境时要考虑到开发平台的安全性和稳定性。该篇文章主要介绍MySQL的几个重要目录以及MySQL数据库的密码管理,接下来就让我们一起学习吧。

Linux MySQL的几个重要目录

1、数据库目录:/var/lib/mysql/。

2、配置文件:/usr/share/mysql(mysql.server命令及配置文件)。

3、相关命令:/usr/bin(mysqladmin mysqldump等命令)。

4、启动脚本:/etc/rc.d/init.d/(启动脚该篇文章件mysql的目录)。

Linux MySQL修改登录密码

Linux MySQL默认没有密码,安装完毕增加密码的重要性是不言而喻的。

1、命令

usr/bin/mysqladmin -u root password 'new-password' 

格式:mysqladmin -u用户名 -p旧密码 password 新密码

2、例子

例1:给root加个密码123456。

键入以下命令 :

[chinastor.com-root@host local]# /usr/bin/mysqladmin -u root password 123456 

注:因为开始时root没有密码,所以-p旧密码一项就可以省略了。

3、测试是否修改成功

1)不用密码登录

[chinastor.com-root@host local]# mysql   ERROR 1045: Access denied for user: 'chinastor.com-root@localhost' (Using password: NO) 

显示错误,说明密码已经修改。

2)用修改后的密码登录

[chinastor.com-root@host local]# mysql -u root -p   Enter password: (输入修改后的密码123456)   Welcome to the MySQL monitor. Commands end with ; or g.   Your MySQL connection id is 4 to server version: 4.0.16-standard   Type 'help;' or 'h' for help. Type 'c' to clear the buffer.   mysql> 

成功! 这是通过mysqladmin命令修改口令,也可通过修改库来更改口令。

Linux MySQL启动与停止

1、启动

MySQL安装完成后启动文件mysql在/etc/init.d目录下,在需要启动时运行下面命令即可。

[chinastor.com-root@host init.d]# /etc/init.d/mysql start  

另外安装程序把MySQL安装成了service,所以在任何目录下都可以用:# service mysql start启动Linux MySQL。

2、停止

/usr/bin/mysqladmin -u root -p shutdown  

或者:

# service mysql stop 

3、自动启动

1)察看mysql是否在自动启动列表中

[chinastor.com-root@host local]# /sbin/chkconfig –list 

2)把Linux MySQL添加到你系统的启动服务组里面去

[chinastor.com-root@host local]# /sbin/chkconfig – add mysql 

3)把Linux MySQL从启动服务组里面删除。

[chinastor.com-root@host local]# /sbin/chkconfig – del mysql 

到此,Linux下MySQL重要目录及密码管理已经介绍完毕,如果想了解更多的MySQL数据库知识,可以看一下这里的文章:http://database.51cto.com/mysql/。

郑重申明:帝往信息科技有限公司以外的任何单位或个人,不得使用该案例作为工作成功展示!