mysql本地、远程连接及'mysql' 不是内部或外部命令错误

mysql布署及python连接mysql问题及Python学习(重要) - CSDN博客  https://blog.csdn.net/sjpljr/article/details/79592601

解决mysql"Access denied for user'root'@'IP地址'"问题 - CSDN博客  https://blog.csdn.net/u012888920/article/details/49700505

问题:控制台cmd窗口键入windows命令:mysql,提示:'mysql' 不是内部或外部命令,也不是可运行的程序或批处理文件

将mysql程序所在文件夹路径,如:C:\Program Files\MySQL\MySQL Server 5.7\bin 添加到系统变量、用户变量

“我的电脑”-“属性”-“高级”-“环境变量”-“系统 变量”,

在系统变量的path项中添加mysql路径(例:mysql安装路径为,C:\Program Files\MySQL\MySQL Server 5.7\bin;)

一、本地登入数据库:——————————————————————————

可以使用的方式(假设用户名:root,密码:a123,数据库:cem):

(方法一)隐藏密码方式:

1、先打开数据库连接,再打开数据库

在cmd控制台窗口windows命令提示符下输入命令:mysql -uroot -p,或mysql -u root -p

提示:Enter password:

输入数据库密码:a123,打开此用户对应的数据库连接,进入mysql命令提示符:mysql>

然后mysql提示符下,输入use cem命令:mysql>use cem    #打开cem数据库

2、直接打开数据库方式:

或者在cmd控制台窗口windows命令提示符下输入命令:mysql -uroot -p cem,或mysql -u root -p cem

MySQL 数据备份与还原 - 逆心 - 博客园  http://www.cnblogs.com/kissdodog/p/4174421.html

 

提示:Enter password:提示下,输入密码:a123,直接打开cem数据库

 

(方法二)显示密码方式:

mysql -uroot -pa123,进入mysql命令提示符:mysql>,再执行use cem命令,进入数据库。

或mysql -uroot -pa123 cem,直接打开cem数据库,并直接进入mysql命令提示符:mysql>

注意:
-u参数可直接加入用户名(有、无空格都可),系统即进入mysql系统提示符。
-p参数须直接输入密码,参数p与密码字符串间不可有空格。
不管使用什么命令,都要有-p参数。


二、Navicat打开MySQL数据库提示:1251……错误。

用Navicat新建数据连接,登录数据库时,提示:1251-Client does not support authentication protocol requested by server;conside upgrading MySQL client.

进入数据库提示符:mysql>

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'aaa';

root是用户名,localhost是ip地址127.0.0.1都是特指本机,mysql_native_password是旧的密码验证机制,aaa是密码。

在Navicat客户端用户名、新密码新建连接,打开数据库,ok。

二、远程登入数据库—————————————————————————————————

mysql帐号默认禁止远程登陆,只允许localhost登录。mysql通过远程进行连接设置:

(一)错误提示:远程连接mysql提示:"Access denied for user 'root'@'IP地址或计算机名称'
python的eric IDE环境中,通过pandas库连接mysql时,如果host='127.0.0.1'或host='localhost'是可以正常连接到mysql服务器的。但是,如果localhost换成本机IP'192.168.2.149'或局域网内其它IP时,则提示错误,具体如下:

import pymysql
conn=pymysql.connect(host='192.168.2.149', port=3306, user='root',password='pd123', db='cem', charset='utf8')
sql='select * from test'
db=pd.read_sql(sql, conn)
print(db)

运行到db=pd.read_sql(sql, conn)时,提示:(1045, "Access denied for user 'root'@'USER-20170911RY' (using password: YES)")

192.168.2.149为服务器IP地址,USER-20170911RY为终端的计算机名称。

(二)错误原因:
授权检查:mysql提示符输入:show grant;

mysql> show grant ;
+---------------------------------------------------------------------+
| Grants for root@localhost                                           |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION        |
+---------------------------------------------------------------------+

权限表中显示的是仅允许从本地计算机(服务器端)登入mysql服务器。

(三)解决方法:

1、通过更改user(用户)表host项远程登入
在localhost登入mysql,更改 "mysql" 数据库里的 "user" 表里的 主机"host" 项,将“localhost”改成“%”。也可通过navicat for mysql软件直接修改user表。
mysql>提示符,需要打开mysql系统数据库下的user数据表。如下:

mysql>use mysql #打开mysql数据库,输出:Database changed
mysql>update user set host = '%' where user = 'root';   #此时mysql提示符下语句须以分号“;”结尾,输出结果:Query OK, 1 row affected
select host, user from user;     #查看用户表中的权限

2、通过授权方式远程登入

mysql>mysql \help      \\显示mysql用法帮助窗口

远程连接时,参数-p需要用空格与密码字符串隔开,否则提示不允许空密码形式连接数据库。(与本地连接数据库有区别)
参数-p代表密码参数,参数-P代表端口参数。要注意大小写字母参数是有区别的。

服务器修改权限:
(1)、在mysql服务器本机上运行:
window cmd控制台命令行提示符输入:mysql -h localhost -u root -p       //输入密码登入MySQL服务器
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION     //赋予其它终端计算机访问服务器权限
mysql>FLUSH PRIVILEGES                                               //刷新权限,修改立即生效
mysql>EXIT          //退出MySQL服务器

privilege美: ['prɪvəlɪdʒ] ,权限,给予权限;grant:允许,同意,美: [ɡrænt];flush:冲洗,刷新,美: [flʌʃ];identfy美: [aɪ'dentɪ.faɪ],识别,发现。

(2). 本机上其它授权方法。
例:授权用户root使用密码pd123,从任意终端计算机连接到mysql服务器。
进入mysql提示符:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'pd123' WITH GRANT OPTION;
mysql>FLUSH PRIVILEGES;
*.*表示数据库及其表,%代表对终端计算机IP地址不作限制。
例:授权用户root以密码pd123,从ip地址192.168.2.149的终端连接到mysql服务器,连接所有数据库
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.2.149' IDENTIFIED BY 'pd123' WITH GRANT OPTION;
mysql>flush privileges;
例:授权用户root以密码pd13,从192.168.2.149终端连接到mysql服务器,选择连接cem数据库,
mysql>GRANT ALL PRIVILEGES ON cem.* TO 'root'@'192.168.2.149' IDENTIFIED BY 'pd123' WITH GRANT OPTION;
mysql>flush privileges;

实现在其它终端上以root身份登录mysql服务器,再次观察权限情况:

mysql> show grants;
+-------------------------------------------------------------+
| Grants for root@%                                           |
+-------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION |
+-------------------------------------------------------------+

用户权限已经变更。

 

<hr>

如何mysql提示符模式:

Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。
C:\Users\Administrator>mysql -upd -ppd123
mysql: [Warning] Using a password on the command line interface can be insecure.


Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.21-log MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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> help
For information about MySQL products and services, visit:
   http://www.mysql.com/
For developer information, including the MySQL Reference Manual, visit:
   http://dev.mysql.com/
To buy MySQL Enterprise support, training, or other products, visit:
   https://shop.mysql.com/


List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
?         (\?) Synonym for `help'.
clear     (\c) Clear the current input statement.
connect   (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
ego       (\G) Send command to mysql server, display result vertically.
exit      (\q) Exit mysql. Same as quit.
go        (\g) Send command to mysql server.
help      (\h) Display this help.
notee     (\t) Don't write into outfile.
print     (\p) Print current command.
prompt    (\R) Change your mysql prompt.
quit      (\q) Quit mysql.
rehash    (\#) Rebuild completion hash.
source    (\.) Execute an SQL script file. Takes a file name as an argument.
status    (\s) Get status information from the server.
tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.
use       (\u) Use another database. Takes database name as argument.
charset   (\C) Switch to another charset. Might be needed for processing binlog
with multi-byte charsets.
warnings  (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.
resetconnection(\x) Clean session context.
For server side help, type 'help contents'

mysql>

sqlite具体用法:

[译] Python 和 Pandas 在 SQLite 数据库中的运用  http://www.360doc.com/content/18/0411/22/9482_744870632.shtml

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值