MySQL执行命令警告_MYSQL命令行输入密码警告问题"mysql: [Warning]"解决

[[email protected] ~]# mysql -uroot -p1234567

mysql: [Warning] Using a password on the command line interface can be insecure.

1.2 解决方法

1.2.1 方法一

1、将密码写入到主配置文件中

[[email protected] ~]# vim /etc/my.cnf

[mysqldump]

user=root

password=1234567

[mysql]

user=root

password=1234567

2、直接使用命令登录,再也无需输入账号密码

[[email protected] ~]# mysql

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 10

Server version: 5.7.18-log Source distribution

Copyright (c) 2000, 2017, 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>

1.2.2 方法二

1、自动配置MYSQL密文密码

该操作会在用户家目录下生成一个隐藏文件".mylogin.cnf",里面记录了MYSQL的密文的密码,只要配置了以后,我们也是直接使用命令登录,再也无需输入账号密码了,如果你想取消,删除此文件即可。

[[email protected] ~]# mysql_config_editor set --user=root --host=localhost --port=3306 --password

Enter password: 输入密码

2、直接使用命令登录,再也无需输入账号密码

[[email protected] ~]# mysql

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 11

Server version: 5.7.18-log Source distribution

Copyright (c) 2000, 2017, 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>

1.2.3 方法三

1、直接使用命令登录,屏蔽错误信息

由于告警信息是标准错误,我们可以将标准错误的输出信息输出为空。

[[email protected] ~]# mysql -uroot -p1234567 2>/dev/null

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 36

Server version: 5.7.18-log Source distribution

Copyright (c) 2000, 2017, 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>

原文:http://blog.51cto.com/10978134/2176000

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 当MySQL安装完成后,默认情况下会生成一个临时密码,该临时密码用于初次登录MySQL。在登录MySQL之前,需要按照如下步骤进行操作: 1. 打开终端或命令行窗口。 2. 输入以下命令并回车: ``` sudo mysql -u root -p ``` 此时系统会要求输入管理员密码输入系统管理员密码并回车。 3. 系统会显示一个警告信息 `[warning] using a password on the command line i`,此警告并不影响登录MySQL。 4. 在终端中,输入以下命令并回车: ``` ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码'; ``` 其中,`新密码`是你要设置的新密码,可以根据需要自行更改。 5. 重新登录MySQL输入以下命令并回车: ``` mysql -u root -p ``` 系统会提示输入密码,此时输入上一步中设置的新密码并回车。 6. 如果登录成功,将会显示MySQL命令行提示符,表示已经成功登录MySQL。 通过以上步骤,就可以使用临时密码登录MySQL,并设置为新密码,以便后续登录时使用。 ### 回答2: MySQL临时密码登录是为了在初始安装或者重置密码后,使用系统生成的临时密码进行登录。在MySQL 5.7及以上版本中,使用临时密码登录需要注意以下步骤: 1. 打开终端或者命令提示符窗口,并输入登录命令:mysql -u root -p。这里的root是用户名,-p表示需要输入密码。 2. 当输入密码时,将临时密码复制(注意:临时密码只有一次使用的机会)。 3. 粘贴临时密码时,可能会遇到"[warning] using a password on the command line is insecure"的警告提示。这是由于MySQL认为在命令行输入密码会暴露给其他用户,从而产生安全风险。 为了避免这个警告提示,我们可以通过以下步骤进行登录: 1. 在终端或者命令提示符窗口输入登录命令,不输入密码mysql -u root -p。 2. 按下Enter键后,会提示输入密码。这时需要将临时密码粘贴至命令行中,然后按下Enter键。 3. 完成以上步骤后,可以成功登录MySQL数据库,并进行后续操作。 请注意,临时密码只在第一次登录时有效,之后需要通过更改密码的方式来设置新的密码。为了安全起见,建议在修改密码后立即登录并将临时密码替换为新密码。 ### 回答3: MySQL的临时密码可以通过以下几个步骤来登录MySQL: 1. 打开命令行窗口,输入mysql -u root -p命令,其中root是MySQL的用户名。 2. 按回车键后,会提示输入密码。此时需要输入临时密码。 3. 输入临时密码后,如果出现[Warning] Using a password on the command line interface can be insecure的警告信息,表示在命令行界面上使用密码可能存在安全风险。 4. 为了解决上述警告,可以通过修改MySQL的配置文件来避免。打开MySQL安装目录下的my.ini(Windows)或者my.cnf(Linux)文件。 5. 在配置文件中找到[mysqld]字段,并在该字段下方添加一行skip-grant-tables。 6. 保存并关闭配置文件,然后重新启动MySQL服务器。 7. 然后再次打开命令行窗口,输入mysql -u root命令,此时应该可以直接登录MySQL,而无需输入密码。 8. 登录成功后,可以执行ALTER USER 'root'@'localhost' IDENTIFIED BY '[新密码]'命令来修改密码,其中[新密码]为想要设置的新密码。 9. 修改密码成功后,再次修改配置文件,将skip-grant-tables一行删除。 10. 重新启动MySQL服务器,然后用新密码登录MySQL即可。 需要注意的是,临时密码是系统生成的,一般会在安装时通过日志文件中给出。此外,为了保证安全性,建议及时修改临时密码并设置一个复杂的密码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值