mysql用户名和密码是root
所以登录-u接用户名,-p接密码,由于没有密码所以直接回车
[[email protected] mysql]# mysql -uroot -p
所以mysql不安全,需要给加密码。
mysql设置密码分两种情况:
第一种情况:没有密码,设置密码
/application/mysql//bin/mysqladmin -u root password ‘new-password‘
第二种情况:有密码,需要修改密码
/application/mysql//bin/mysqladmin -u root -h web01 password ‘new-password‘
设置密码:
[[email protected] mysql]# /application/mysql//bin/mysqladmin -u root password ‘oldboy123‘
设置完密码后直接,输入mysql就无法登陆
[[email protected] mysql]# mysql ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)
需要使用密码才可以登陆mysql -uroot -poldboy123
[[email protected] mysql]# mysql -uroot -poldboy123 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 5.5.49 MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. mysql>
修改mysql的密码为123456
[[email protected] mysql]# mysqladmin -uroot -poldboy123 password 123456 [[email protected] mysql]# mysql -uroot -poldboy123 ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES) [[email protected] mysql]# mysql -uroot -p123456 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 11 Server version: 5.5.49 MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. mysql>
登陆mysql后,会在history中留下mysql密码,如何避免密码泄露?
方法1:history -c清空所有历史记录
[[email protected] mysql]# history -c [[email protected] mysql]# history 69 history
方法2:只清空带有密码的一条记录的那行命令:history -d 历史记录号
[[email protected] mysql]# history 69 history 70 mysql -uroot -p123456 71 history [[email protected] mysql]# history -d 70 [[email protected] mysql]# history 69 history 70 history 71 history -d 70 72 history [[email protected] mysql]#
时间: 2024-10-10 04:54:19