This post isn't duplicate. I already referred this post and this post but the answers doesn't help
I am trying to execute a code in mySQL client window. HowEVER,I get the below error
The used command is not allowed with this MySQL version
What I did
SET GLOBAL local_infile = 1;
SHOW VARIABLES LIKE 'local_infile';
I executed the above commands in MySQL 8.0 Command Line Client
When I tried to do the same thing in MySQL Shell, I get the below error as Unexpected identifier
I am assuming MySQL Shell is the server. Do we have to do this at both client and server side?
How do I resolve this? In addition, whenever I launch command line client, I am only prompted to type password. So I am not able to pass it as a parameter. my clinet looks like as shown below
But how do I pass the below parameters while logging in then?
mysql -u abcd -p password_here --local-infile=1
I am new to MySQL and can you guide me?
Q1:
To run sql commands in MySQL Shell you need to change from default JS to sql
R1:
type \sql to change from js to sql
mysql-js> \sql
Q2:
so I am not able to pass it as a parameter
For this you must be selecting 'MySQL x.x Command Line Client' under windows search.
To resolve you need to have mysql bin folder in environment path or do the below step to access
R2:
Goto "C:\Program Files\MySQL\MySQL Server x.x\bin" this is windows default path unless you change.
Then in the address bar if you click it will select ( i.e. C:\Program Files\MySQL\MySQL Server 5.7\bin) there just type cmd (Note: now in the address bar you will see only cmd) then press enter.
Once cmd window opens with the mysql path like below
C:\Program Files\MySQL\MySQL Server 5.7\bin>
Type blah..blah.. blah
mysql -u abcd -p password_here --local-infile=1
Note: If you just parse -p instead of -ppassword it will ask for password after that. So if you are going to type the password directly then type -pyourpass there will not be any spaces between -p and password
I have a Win7 machine running PHP/MySQL/Apache and I have MySQL Administrator, MySQL Manager for MySQL installed along with a few other tools like Toad MySQL 6.0...
I was looking for a solution for some utf-8 issues I've been having and the majority of solutions (ie this one) say to run a set of commands such as mysqldump etc... But HOW do I run a command on a windows machine? I've tried executing it as an SQL script, running from the Windows Run command like
"C:\Program Files\MySQL\MySQL Server 5.1\bin\" mysqldump MY_DB -uroot --opt --quote-names --skip-set-charset --default-character-set=latin1 >c:\MY_DB_latin1.sql
but without luck. Any suggestions would be very helpful.
The problem is the space between "C:\Program Files\MySQL\MySQL Server 5.1\bin\" and mysqldump. This should read "C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqldump".
Adding the .exe is optional: "C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqldump.exe".
If you want to execute MySQL commands instead of dumping the database you should use mysql.exe: "C:\Program Files\MySQL\MySQL Server 5.1\bin\mysql.exe". Use the -? option to get an overview of the command line options.
you have a space before mysqldump which is not required.
Also it should be mysqldump.exe
Win+R -> cmd -> OK
is a Windows command line.
Here you can type (assuming that C:\Program Files\MySQL\MySQL Server 5.1 is a correct path to your MySQL directory and MY_DB is your database name):
"C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqldump.exe" MY_DB -uroot --opt --quote-names --skip-set-charset --default-character-set=latin1 >c:\MY_DB_latin1.sql
Here, you'll be able to see the output (most likely you will need -uroot -p, because your root account is password-protected, isn't it?).
If you'd like to paste a command, right-click and select "Paste" - Ctrl-V won't work here.
I installed MySql 4.1(because that what is running on my server), I got a file that is a dump of my database. It is about 4.6 GB.
I put that file in same location as MySql.exe lives C:\Program Files\MySQL\MySQL Server 4.1\bin
Then I go to command line and type in:
mysql -h localhost -u root -p [database name] < mysqlDump.sql
I get message back 'The system cannot find the file specified.'
What file is it referring to? The mysqlDump.sql?
Even when I specify the full path to the mySqlDump.sql file, I get the same message.
mysql -h localhost -u root -p [database name] < C:\Program Files\MySQL\MySQL Server 4.1\bin\mysqlDump.sql
I'm running MySql 4.1 on Windows7
update found out my mistake. My folder was hiding file extensions. Somehow when I saved the file on my machine I gave it an extra .sql extension. So the file had a name of mysqlDump.sql.sql
You are probably not in the right directory when you make the call.
Go there:
cd "C:\Program Files\MySQL\MySQL Server 4.1\bin"
or specify the input file's absolute path:
mysql -h localhost -u root -p [database name] < "C:\Program Files\MySQL\MySQL Server 4.1\bin"
Use TAB key when you are starting typing mysqlDump... to ensure that your file is there and you have privileges for it.
Tab key in command line will complete filename or not.
This will give you some information if the file exists and if you have permissions to that file. Maybe it was created from other operating system user account and you have no read privileges.
I put that file in same location as MySql.exe lives C:\Program
Files\MySQL\MySQL Server 4.1\bin
This is not good idea, because regular operating system user accoung may have no privileges to write in Program Files directory.
To do it properly I would add C:\Program Files\MySQL\MySQL Server 4.1\bin to the PATH environment variable (link with howto). After you do this you will be able to run MySQL executable files from anywhere you want (like your desktop or documents folder for example) without messing around in Program Files. You can place your working file at location where you have all privileges and work on it from the command line.
Hi I have installed MySQL from oracle website, but did not get a "MySQL Command Line" option under MySQL in Programs menu.
So I looked up on this site how to execute sql queries from DOS command prompt.
I found an answer on this site that advised to type in something like: sql root u- p- etc. but this does not work.
Can anyone advise me the syntax to use to go into sql from DOS, or direct me to the answer described above (I cannot locate it)
I use Windows 7 and downloaded the ODBC driver, too.
Many thanks.
Unless MySQL's bin directory is in your PATH variable, you will need to either be in the directory, or write an absolute path to it to execute.
Try something like this (depending on your installation):
cd "C:\Program Files\MySQL\MySQL Server 5.5\bin"
mysql -uroot
Alternatively, you could type this directly:
"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql.exe" -uroot
cd/
cd wamp
cd bin
cd mysql
cd mysql5.0.51b
#################################
note use your own version of mysql, mine is 5.0.51b
########################################
cd bin
mysql -h localhost -u root -p
////////////////////////////////
note -p that is if u use a password
////////////////////////////////////////
after this line of codes you have this
welcome note telling you the server version of mysql and your connection id
If you navigate to the bin directory of the program you just installed then type "mysql.exe"
Have a look at this guide if you get stuck with the commands
Determine the path of your MySQL installation, and add it to PATH environment variable.
SET PATH=%PATH%;C:\MySQL\bin
The above example assumes MySQL to be installed in C:\MySQL directory.
Once path is set, then you can directly execute
mysql -u root
Which logs into MySQL as root user. The -p flag can be used if password is required
It is required to execute SET PATH every time, hence you may make a batch file.
I have a database called nitm. I haven't created any tables there. But I have a SQL file which contains all the necessary data for the database. The file is nitm.sql which is in C:\ drive. This file has size of about 103 MB. I am using wamp server.
I have used the following syntax in MySQL console to import the file:
mysql>c:/nitm.sql;
But this didn't work.
From the mysql console:
mysql> use DATABASE_NAME;
mysql> source path/to/file.sql;
make sure there is no slash before path if you are referring to a relative path... it took me a while to realize that! lol
Finally, i solved the problem. I placed the `nitm.sql` file in `bin` file of the `mysql` folder and used the following syntax.
C:\wamp\bin\mysql\mysql5.0.51b\bin>mysql -u root nitm < nitm.sql
And this worked.
If you are using wamp you can try this. Just type use your_Database_name first.
Click your wamp server icon then look for MYSQL > MSQL Console then run it.
If you dont have password, just hit enter and type :
mysql> use database_name;
mysql> source location_of_your_file;
If you have password, you will promt to enter a password. Enter you password first then type:
mysql> use database_name;
mysql> source location_of_your_file;
location_of_your_file should look like C:\mydb.sql
so the commend is mysql>source C:\mydb.sql;
This kind of importing sql dump is very helpful for BIG SQL FILE.
I copied my file mydb.sq to directory C: .It should be capital C: in order to run
and that's it.
In windows, if the above suggestion gives you an error (file not found or unknown db) you may want to double the forward slashes:
In the mysql console:
mysql> use DATABASE_NAME;
mysql> source C://path//to//file.sql;
Ok so, I'm using Linux but I think this holds true for Windows too.
You can do this either directly from the command prompt
> mysql -u <user name> -p<password> <database name> < sqlfilename.sql
Or from within the mysql prompt, you can use:
mysql>source sqlfilename.sql
But both these approaches have their own benefits in the results they display.
In the first approach, the script exits as soon as it encounters an error. And the better part, is that it tells you the exact line number in the source file where the error occurred. However, it ONLY displays errors. If it didn't encounter any errors, the scripts displays NOTHING. Which can be a little unnerving. Because you're most often running a script with a whole pile of commands.
Now second approach (from within the mysql prompt) has the benefit that it displays a message for every different MySQL command in the script. If it encounters errors, it displays the mysql error message but continues on through the scripts. This can be good, because you can then go back and fix all the errors before you run the script again. The downside is that it does NOT display the line numbers in the script where the errors were encountered. This can be a bit of a pain. But the error messages are as descriptive so you could probably figure out where the problem is.
I, for one, prefer the directly-from-OS-command line approach.
If you are using xampp
C:\xampp\mysql\bin\mysql -uroot -p nitm < nitm.sql
You are almost there
use
mysql> \. c:/nitm.sql;
You may also access help by
mysql> \?
For localhost on XAMPP. Open a cmd window and type
cd C:\xampp\mysql\bin
mysql.exe -u root -p
Attention! No semi-colon after -p
Enter your password and type
use database_name;
to select the database you need.
Check if your table is there
show tables;
Import from your sql file
source sqlfile.sql;
I have put my file on C:\xampp\mysql\bin location in order to don't mix up with locations of sql file.
Try:
mysql -u username -p database_name < file.sql
Check MySQL Options.
Note: It is better to use the full path of the SQL file file.sql.
Don't forget to use
charset utf8
If your sql file is in utf-8 :)
So you need to do:
cmd.exe
mysql -u root
mysql> charset utf8
mysql> use mydbname
mysql> source C:\myfolder\myfile.sql
Good luck ))
In Linux I navigated to the directory containing the .sql file before starting mysql. The system cursor is now in the same location as the file and you won't need a path. Use source myData.sql where my date is replaced with the name of your file.
cd whatever directory
mysql - p
connect targetDB
source myData.sql
Done
from the command line (cmd.exe, not from within mysql shell) try something like:
type c:/nite.sql | mysql -uuser -ppassword dbname
Does your dump contain features that are not supported in your version of MySQL? You can also try to remove the starting (and ending) MySQL commented SET-statements.
I don't know if your dump comes from a Linux version of MySQL (line endings)?
I have installed my wamp server in D: drive so u have to go to the following path from ur command line->(and if u have installed ur wamp in c: drive then just replace the d: wtih c: here)
D:\>cd wamp
D:\wamp>cd bin
D:\wamp\bin>cd mysql
D:\wamp\bin\mysql>cd mysql5.5.8 (whatever ur verserion will be displayed here use keyboard Tab button)
D:\wamp\bin\mysql\mysql5.5.8>cd bin
D:\wamp\bin\mysql\mysql5.5.8\bin>mysql -u root -p password db_name < "d:\backupfile.sql"
here root is user of my phpmyadmin
password is the password for phpmyadmin so if u haven't set any password for root just nothing type at that place,
db_name is the database (for which database u r taking the backup)
,backupfile.sql is the file from which u want ur backup of ur database and u can also change the backup file location(d:\backupfile.sql) from to any other place on your computer
mysql>c:/nitm.sql;
That would write the output of the mysql command to 'nitm.sql;' (What's the ';' supposed to do?) Assuming you've got a copy of the original file (before you overwrote it) then:
mysql < c:/nitm.sql
Export Particular DataBases
djimi:> mysqldump --user=root --host=localhost --port=3306 --password=test -B CCR KIT >ccr_kit_local.sql
this will export CCR and KIT databases...
Import All Exported DB to Particular Mysql Instance (You have to be where your dump file is)
djimi:> mysql --user=root --host=localhost --port=3306 --password=test < ccr_kit_local.sql
In Windows OS the following commands works for me.
mysql>Use <DatabaseName>
mysql>SOURCE C:/data/ScriptFile.sql;
No single quotes or double quotes around file name. Path would contain '/' instead of '\'.
For those of you struggling with getting this done trying every possible answer you can find on SO. Here's what worked for me on a VPS running Windows 2012 R2 :
Place your sql file wherever the bin is for me it is located at C:\Program Files\MySQL\MySQL Server 8.0\bin
Open windows command prompt (cmd)
Run C:\Program Files\MySQL\MySQL Server 8.0\bin > mysql -u [username] -p
Enter your password
Run command use [database_name];
Import your file with command source C://Program Files//MySQL//MySQL Server 8.0//bin//mydatabasename.sql
It did it for me as everything else had failed. It might help you too.