SQL File won't restore - mysql

What I have done:
mysql -u root -p -h localhost gx < gxe.sql
Result:
[root#jony html]# mysql -u root -p -h localhost gx < gxe.sql
Enter password:
[root#jony html]#
It actually doesn't do anything.. I tried refreshing my SQL client (Heidi SQL), and still nothing?.
What have I done wrong? Thanks!
OS: CentOS 6 - Linux

mysql and mysqldump have slightly different syntax
mysql needs -D parameter to set the database.
So try
mysql -u root -p -h localhost -D gx < gxe.sql

Related

Connect to different port using MySql Command Line Client

By default I am being connected to port 3309.I need to connect to port 3307.How do I do that?
Use -P parameter, like this:
mysql -h 127.0.0.1 -P 3307 -u user_name -p database_name
Important: if you connecting to localhost - use -h 127.0.0.1, NOT localhost, because MySQL will connect by file socket, not by TCP
From command line, assuming you are on the same host, have you tried :
mysql --user root --password (mypassword) --host=localhost --port=33061
In server name specify custom port when not using default one (you can imply it only when is the standard mysql port 3306)
$servername = "localhost:33061";
you can use -P (uppercase) or --port=portnumber
sample
mysql -u root -P 13306 -p databasename
or
mysql -u root --port=13306 -p databasename
Enter this command changing your details.
after that MySQL requests the password for the connection, then enter the password.
mysql --user=user1 --host=127.16.38.1 --port=25060 -p
especially consider about -p and double Hyphen --
I am giving simple way, one liner which summarizes.
mysql -u root -p --port=3316 // I have MySQL port 3316, instead of default 3306
If the --port=3316 is not provided, then MySQL Cli protocol will try with the default port, without asking.
For any other user
mysql -u anotheruser -p --port=3316

How do i import into mysql daily via cron or ssh

I want to write a cron job to INSERT INTO 6 tables. I know that :
The tables will always exist and will be empty, awaiting records
I will have 6 .sql dump files On the server which will be ready to be imported.
The format of the files are exactly as created by the phpMyAdmin export tool
i.e. all already have a single INSERT INTO tablename line and multiple parenthisised value lines.
All have foreign-key constraints set to off before the insert statement and toggled on again after the inserts.
i wanted to do all from within PHP but on a shared hosting the exec() func is disabled and so is the FILES priviledge so my options are dwindling.
I'm looking for a way to do the above from cPanel cron or SSH tools in cPanel. CRON would be my first choice since i'm unfamiliar with SSH.
Do i run this line 6 times (for each file) or can i consolidate it into one cron or ssh command? p.s. also do i use absolute or relative paths to the .sql dump files
mysql -h localhost -u myusername -p mypassword mycatalogdb < 'sqlcronfiles/dump-1.sql'
mysql -h localhost -u myusername -p mypassword mycatalogdb < 'sqlcronfiles/dump-2.sql'
mysql -h localhost -u myusername -p mypassword mycatalogdb < 'sqlcronfiles/dump-3.sql'
mysql -h ... etc ...
thanks
You can create a task.sh file located at /home/youruser/ and inside you can put the following:
#!/bin/bash
mysql -h localhost -u myusername -p mypassword mycatalogdb < 'sqlcronfiles/dump-1.sql'
mysql -h localhost -u myusername -p mypassword mycatalogdb < 'sqlcronfiles/dump-2.sql'
mysql -h localhost -u myusername -p mypassword mycatalogdb < 'sqlcronfiles/dump-3.sql'
mysql -h localhost -u myusername -p mypassword mycatalogdb < 'sqlcronfiles/dump-4.sql'
mysql -h localhost -u myusername -p mypassword mycatalogdb < 'sqlcronfiles/dump-5.sql'
mysql -h localhost -u myusername -p mypassword mycatalogdb < 'sqlcronfiles/dump-6.sql'
Then, to execute this cron, from cPanel, you create a Cronjob, configure the time as needed and the command it should execute is:
/home/youruser/task.sh
And you are done.
I hope it works for you

mysql login failing with -h option

If I try to login into mysql with -h option, login fails
mysql -u keystone_admin -h IP_ADDRESS -p
If I use mysql without -h option login is successful
mysql -u keystone_admin -p
Let me know how to resolve this issue.

mysql syntax error near expected new line in terminal mac

I am running the following command as given on web to connect the mysql data base but it gives syntax error new line expected here is the command i am entering.
mysql -<hivelettest.c0e9graawyhr.us-west-2.rds.amazonaws.com -p 3306 -u <user> -p <pass>
The <> parts of the command were given to show where the username and password should go. They shouldn't be in the command:
mysql -hmydbserver.co.uk -P3306 -u username -pmypassword
Try this, and make sure that there is no space between -u or -p. And if you are using PORT you need to write it differently. The password parameter must then be --password=
mysql -hmydbserver.co.uk -P 3306 -uUsername --password=yourpassword
Since 3306 is the standard one you could leave it out, then you can write it like this.
mysql -hmydbserver.co.uk -uUsername -pYourpassword
If you want to pass with a command, do it like this.
mysql -hmydbserver.co.uk -P 3306 -uUsername --password=yourpassword nameofdatabase
-e "SELECT * FROM tablename"

Database master-slave replication error

I am trying to replicate my mysql database using the master slave replication. On the slave machine, when i try to run this query, i get stuck.
mysqldump -h 10.124.2.34 bank --password='' --user='root' | mysql bank --password='' --user='root'
Any idea what I am doing wrong?
Try this :
Total DB dump :
mysqldump -uroot -h -p pwd -P db_name | mysql -uroot -p pwd -P db_name
Only Table copy
mysqldump -uroot -h -p pwd -P db_name | mysql -uroot -p pwd -P db_name
It's working for me.