执行SQL脚本
一、进入Linux的MySQL
1、未设定密码时进入
直接输入
mysql
或者
mysql -h 127.0.0.1 -u root
2、有密码进入
mysql -h 127.0.0.1 -u root -p
按回车后输入密码
3、进入docker里面的MySQL
①查看docker中mysql服务名称
docker ps
②进入docker中的mysql
docker exec -it br-mysql bash
mysql -h 127.0.0.1 -u root-p
③输入密码,即可完成登录
[root@br-apm-002 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d3fa99ca0475 ibr.cc/kafka/kafka:2.11-0.10.2.2.1 "/data/br/base/kafka…" 20 hours ago Up 20 hours br-kafka
35e46b4b0d8f ibr.cc/dataview/nacos:1.4.0 "/bin/sh -c /data/br…" 20 hours ago Up 20 hours br-nacos
e628fabb3ec4 ibr.cc/redis/redis:5.0.6 "/data/br/base/redis…" 20 hours ago Up 20 hours br-redis7200
b1e5cf49a63c ibr.cc/redis/redis:5.0.6 "/data/br/base/redis…" 20 hours ago Up 20 hours br-redis7100
8d5581d90377 ibr.cc/mysql/mysql:8.0.27 "docker-entrypoint.s…" 20 hours ago Up 20 hours br-mysql
You have mail in /var/spool/mail/root
[root@br-apm-002 ~]# docker exec -it br-mysql bash
root@br-apm-002:/# mysql -h 127.0.0.1 -u root-p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 196561
Server version: 8.0.27 MySQL Community Server - GPL
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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脚本
1、使用工具执行SQL脚本(使用Navicat)
2、手动执行(在Mysql安装机器上)
将执行文件传输到mysql安装目录下
[root@xxx mysql]# ll -tr
total 420
drwxr-xr-x 2 27 27 4096 Jun 4 2019 binlog
drwxr-xr-x 2 27 27 4096 Oct 29 12:03 iblog
drwxr-xr-x 2 27 27 4096 Oct 29 12:10 log
drwxr-xr-x 2 27 27 4096 Nov 19 14:51 run
-rw-r--r-- 1 2048 2048 3826 Nov 19 14:56 mysql.cnf
-rw-r--r-- 1 root root 25 Nov 25 19:28 test_xxx.sql
drwxr-xr-x 2 27 27 4096 Nov 25 15:38 tmp
drwxr-xr-x 22 27 27 4096 Dec 2 15:05 data
进入MySQL:
mysql -u root
mysql -u user -p #这种是需要密码的账户登录指令,enter后输入密码即可
检查现有数据库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| druiddb |
| mysql |
| nacos_config |
| performance_schema |
| phpmyadmin |
| sys |
| zeusdb |
+--------------------+
8 rows in set (0.00 sec)
执行SQL脚本
这一步有个特别蛋疼的点:进入mysql时的目录必须要和脚本存放位置的目录一致
mysql> source test_xxx.sql;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| druiddb |
| mysql |
| nacos_config |
| performance_schema |
| phpmyadmin |
| sys |
| test_xxx |
| zeusdb |
+--------------------+
9 rows in set (0.00 sec)