Many times we need to run a SQL script and we do not have graphical tools such as: phpMyAdmin or Adminer so we need to use the command line and use the mysql shell and follow one of the following methods:
1. Execute SQL script in direct way
$ mysql -u user -p data-base < script.sql
2. Authenticate and then run SQL script
$ mysql -u usr -p data-base
Then
source script.sql;
Or
. script.sql;
If script.sql file is not found in the current directory, then you must specify the path where it is located
Further readings
- man mysql
Spanish video associated
Administering MySQL from the command line, 10 (15)
- How to install MySQL 5.7 on CentOS 7
- How to install MySQL 8.0 in Ubuntu 20.04
- How to install MySQL 8.0 in Debian
- How to install MariaDB on Alpine Linux
- How to install MariaDB on NetBSD?
- MySQL 8.0, change root password
- MySQL server administration – Basic
- Create / modify / delete tables in MySQL
- MySQL user administration
- MySQL – Execute SQL script
- Disable innodb engine in MySQL
- Show MySQL storage engines
- Character set available in MySQL
- Connect to a MySQL server from the LAN
- MySQL can not write in the /tmp dir