mysql 命令行执行sql文件
一、登陆远程mysql服务
命令格式为:mysql -h ip -u root -p -P port
标识密码的p
为小写,指定端口的P
为大写
例如:
mysql -h 10.8.0.253 -u root -p -P 3306
回车后,键入密码
zhishengjie@zhishengjiedeMacBook-Pro ~ % mysql -h 10.8.0.253 -u root -p -P 3306
Enter password:
登陆成功
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 49785
Server version: 5.7.28 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, 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>
二、命令行状态下,执行sql文件
-
选择使用的数据库
mysql> use ucdb Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed
-
使用
source
执行 sql 文件mysql> source /Users/zhishengjie/Downloads/district.sql
三、 备注
操作是简单,但是因为偶尔使用,总是记不住,所以就记录一下吧