mysql用户名和密码是root
所以登录-u接用户名,-p接密码,由于没有密码所以直接回车
[root@web01 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'
设置密码:
1
|
[root@web01 mysql]
# /application/mysql//bin/mysqladmin -u root password 'oldboy123'
|
设置完密码后直接,输入mysql就无法登陆
1
2
|
[root@web01 mysql]
# mysql
ERROR 1045 (28000): Access denied
for
user
'root'
@
'localhost'
(using password: NO)
|
需要使用密码才可以登陆mysql -uroot -poldboy123
1
2
3
4
5
6
7
8
9
10
|
[root@web01 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
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@web01 mysql]
# mysqladmin -uroot -poldboy123 password 123456
[root@web01 mysql]
# mysql -uroot -poldboy123
ERROR 1045 (28000): Access denied
for
user
'root'
@
'localhost'
(using password: YES)
[root@web01 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清空所有历史记录
1
2
3
|
[root@web01 mysql]
# history -c
[root@web01 mysql]
# history
69
history
|
方法2:只清空带有密码的一条记录的那行命令:history -d 历史记录号
1
2
3
4
5
6
7
8
9
10
11
|
[root@web01 mysql]
# history
69
history
70 mysql -uroot -p123456
71
history
[root@web01 mysql]
# history -d 70
[root@web01 mysql]
# history
69
history
70
history
71
history
-d 70
72
history
[root@web01 mysql]
#
|
本文转自sandshell博客51CTO博客,原文链接http://blog.51cto.com/sandshell/1958824如需转载请自行联系原作者
sandshell