How to execute script file in MySQL

script file contains list of commands saved in with .sql/.txt or other extension. To import or export file in MySQL, use must be granted FILE permission.

Steps to execute script file in MySQL:

1. Create a file(.sql extension): We are going to get list of users in MySQL using the file

prvr@ubuntu:~$ cat > getlistofusers.sql select user from mysql.user; prvr@ubuntu:~$ ls -ltrh *getlist* -rw-rw-r-- 1 prvr prvr 29 Sep 6 17:41 getlistofusers.sql

2. Run the query

prvr@ubuntu:~$ mysql -u root -p < getlistofusers.sql #This will prints output on screen Enter password: user phpadmin admin debian-sys-maint mgeorge mysql.session mysql.sys root skalpesh

3. To export the output of script to another file.

prvr@ubuntu:~$ mysql -u root -p < getlistofusers.sql >listofusers.sql Enter password: prvr@ubuntu:~$ ls -ltrh *listof* -rw-rw-r-- 1 prvr prvr 83 Sep 6 18:01 listofusers.sql prvr@ubuntu:~$ cat listofusers.sql user phpadmin admin debian-sys-maint mgeorge mysql.session mysql.sys root skalpesh prvr@ubuntu:~$

CheapSexCams
Responses are currently closed, but you can trackback from your own site.

Comments are closed.

Powered by k2schools
%d bloggers like this: