Failed to open file ‘/ home/mydatabase. SQL’, error: 2 when running SQL script in docker image MySQL in Linux
Today, an error occurred when using docker in centos7 to start MySQL and run SQL script files. The error information is as follows:
mysql> source /home/mydatabase.sql;
ERROR:
Failed to open file '/home/mydatabase.sql', error: 2
After checking the Internet, the cause of the error should be the problem of path matching. The default path is the installation path of MySQL, so MySQL can only access all directories and files under its source directory. The solution is to directly specify the SQL script file to run when logging in. The specific steps are as follows:
first log in to MySQL and create the database to be used. The name of the database I created is Mydatabase1
root@4994c041aa3a: mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.36 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> create database mydatabase1;
Exit MySQL and log in again by running SQL script files
# Here mydatabase1 is the database created in the first step, and the file after'<' is the path of the sql script file to be run
root@4994c041aa3a: mysql -uroot -p mydatabase1 < /home/mydatabase.sql
log in again and find that the file has run successfully
root@4994c041aa3a: mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.36 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| mydatabase1 |
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql> use mydatabase1;
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
mysql> show tables;
+-----------------------------+
| Tables_in_mydatabase1 |
+-----------------------------+
| t_disk |
| t_crl |
| t_menu |
| t_user |
+-----------------------------+
4 rows in set (0.00 sec)
Supplement:
# Docker start MySQL command under CentOS7
docker pull mysql:5.7
docker run -tid --name mysql -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 mysql:5.7
docker exec -it mysql /bin/bash
mysql -uroot -p
Enter password:
Read More:
- [Solved] java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corres
- java.sql.SQLException: Disk full (/tmp/#sql_1eaa2_60.MAI); waiting for someone to free some space
- MySQL Build table error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL ser
- MySQL 8.0.12 runs SQL error #1055 [How to Solve]
- MySQL Change password failure prompt: ERROR 1064(42000):You have an error in your SQL syntax: check the corresponds to your M
- [Modified] Hive SQL Error: SQL ERROR [10004] [42000]: Error while compiling statement: FAILED: SemanticException [Error
- MYSQL Use cmd to change root password error: ERROR 1064 (42000): You have an error in your SQL syntax; check the manual tha
- [Solved Perfectly] MySQL ERROR 1064 (42000): You have an error in your SQL syntax;
- Bulk Update Error: #Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the m
- Mysql 8.0.13 Enabling remote access (ERROR 1064 (42000): You have an error in your SQL syntax; check the manual th)
- [Solved] MYSQL Start Project Error: this is incompatible with sql_mode=only_full_group_by
- [Solved] SQL Error: Method queryTotal execution error of sql
- [Solved] Sphinx macos sql_connect: failed to load libmysqlclient
- Centos7 Initialize mysql Error: Could not open file ‘/usr/local/mysql/log/mysqld.log‘ for error logging: Per
- SQL Developer error: Unable to find a Java Virtual Machine solution
- [Solved] MYSQL 5.7 gruop by eRROR: this is incompatible with sql_mode=only_full_group_by
- MYSQL gruop by Error: this is incompatible with sql_mode=only_full_group_by
- [Solved] MySQL Error: ERROR 1055 (42000)sql_mode=only_full_group_by
- [Solved] error {dataSource-1} init error java.sql.SQLException: com.mysql.cj.jdbc.Driver
- Introduction to Relational Databases in SQL