Extract mysql Database from CommandLine - apache

I am using wamp server but something happend to it and now there is no way to make it come back to life. I only have access to mysql command line, and i have some important databases there.
How can i export the database using commandline?
please help.

mysqldump -h localhost --routines -u root -p dbname

If the mysql server is not behaving normally, you might have some corrupted tables. It happens usually after an unscheduled restart. mysqldump won't be able to export corrupted tables.
If the mysql server is running, try connecting to it using phpmyadmin and use the built in tools to fix and check the tables
if the mysql server fails to start, check the log files and use the mysql command line tools to fix the issues
myisamchk --silent --force --fast --update-state /var/lib/mysql/dbname/*.MYI
(http://www.thegeekstuff.com/2008/09/how-to-repair-corrupted-mysql-tables-using-myisamchk/)

First try to connect to Mysql server using the command line
mysql -uUsername -p and press enter.This will prompt for password.Enter the mysql server password.
Then use the mysqlcheck command to repair the server in case corruption has occured
COmmand for mysql-check : mysqlcheck --repair --use-frm --all-databases

I think you can just copy the folders of the database to create a backup of MySQL databases.
Used to work.

Related

Run psql query using ssh

I wrote a file.sh to execute psql query from remote sever. I'm stuck on the first step:
ssh user#myserver.com "psql database"
=> Nothing happens
I tried several different syntaxes that I found on google, but nothing works for me.
Manualy I process like this without problem:
$ ssh myserver
$ psql database
database=> select foo from table;
I don't know what I missed (it's my first bash script)
I use SSH every day to connect to my work server and use ssh user#server. From there, I am able to run files, connect to my database, etc.

Migrate mysql users to another server

I have created a mysqldump --all-databases and transferred all my databases to the new server. It didn't work as debian-sys-maintusers password didn't match. So I change the password of this user. After that I restart my server and got this error.
ERROR 1577 (HY000) at line 1: Cannot proceed because system tables
used by Event Scheduler were found damaged at server start ERROR 1547
(HY000) at line 1: Column count of mysql.proc is wrong. Expected 20,
found 16. The table is probably corrupted
I dont know how many more errors will come after this. So I thought create dump with only databases which are associated with my applications (mysqldump --databases).
Now how do migrate the users? Is there any standard way?
More Information:
New Server version: 5.1.63-0+squeeze1 (Debian)
Old Server version: 5.0.51a-24+lenny5 (Debian)
You probably need to run mysql_upgrade, since your MySql versions are different.
As a general rule, however, do not copy the mysql system schema from one server to another. As a consequence, and as far as I know, there is no "standard" way of copying users and user privileges from one server to another.
If you really want/need to do it, try the following:
$> mysql --silent --skip-column-names -e"show grants for user#host"
The above outputs GRANT statements that you can feed straight away into your target server to create the user and give the same authorisations.
However, if your target server is empty, you could just move the whole data folder from your old server to the new server, and then run the standard upgrade procedure from 5.0 to 5.1 on the new server.

SQL Server 2005 Express

Can anyone decipher this error message? Somebody gave me a SQL script and when I run it, I get this error:
Thanks.
If it is an instance of SQL Server Express, it is likely a named instance. So try adding -S .\SQLEXPRESS to the command.
Also see this blog post for common troubleshooting ideas: http://blogs.msdn.com/b/sql_protocols/archive/2007/03/31/named-pipes-provider-error-40-could-not-open-a-connection-to-sql-server.aspx
Sounds like you might not have remote connections enabled on the SQL Server you are trying to run this script against. Take a look at this article:
http://support.microsoft.com/kb/914277
You do not have the Server name parameter specified in there.
`osql -U sa iP -i dbattach05.sql`
You might want this
`osql -S ServerOrInstanceNameGoesHere -U sa iP -i dbattach05.sql`
You might need to do something like this if its an Express edition: http://www.linglom.com/2009/03/28/enable-remote-connection-on-sql-server-2008-express/

Problem with a northwind database installation

I have a instnwnd.sql which is a script file for northwind database installation. I don't know how to install this database. I have tried the procedure http://msdn.microsoft.com/en-us/library/ms227484(v=vs.90).aspx but I could not succeed. The error comes out to be "The user is not associated with a trusted sql server connection" I read some where u can do it using query analyser, but what is the sql statement for that ?? Somebody please help me.
Thanks in anticipation
To overcome the "sa" problem I used this and it worked for me.
C:\Users\UserName>sqlcmd -E -i c:\path\to\instnwnd.sql
The website I got this from is
Install Northwind Database.
When you followed the instructions from the MSDN page, and you ran
osql -U sa -P [password] -i instnwnd.sql
you did see the note about replacing [password] with the actual administrative password you created when you installed SQL Server, right?
Note For [password], type the system administrator password that you
created earlier.
Just open the instnwnd.sql file (which is plain text) in Notepad, copy all the text, and paste it into the query window in SQL Server Management Studio. Then press F5 to run the SQL script.

Error importing SQL dump into MySQL: Unknown database / Can't create database

I'm confused how to import a SQL dump file. I can't seem to import the database without creating the database first in MySQL.
This is the error displayed when database_name has not yet been created:
username = username of someone with access to the database on the original server.
database_name = name of database from the original server
$ mysql -u username -p -h localhost database_name < dumpfile.sql
Enter password:
ERROR 1049 (42000): Unknown database 'database_name'
If I log into MySQL as root and create the database, database_name
mysql -u root
create database database_name;
create user username;# same username as the user from the database I got the dump from.
grant all privileges on database_name.* to username#"localhost" identified by 'password';
exit mysql
then attempt to import the sql dump again:
$ mysql -u username -p database_name < dumpfile.sql
Enter password:
ERROR 1007 (HY000) at line 21: Can't create database 'database_name'; database exists
How am I supposed to import the SQL dumpfile?
This is a known bug at MySQL.
bug 42996
bug 40477
As you can see this has been a known issue since 2008 and they have not fixed it yet!!!
WORK AROUND
You first need to create the database to import. It doesn't need any tables. Then you can import your database.
first start your MySQL command line (apply username and password if you need to)
C:\>mysql -u user -p
Create your database and exit
mysql> DROP DATABASE database;
mysql> CREATE DATABASE database;
mysql> Exit
Import your selected database from the dump file
C:\>mysql -u user -p -h localhost -D database -o < dumpfile.sql
You can replace localhost with an IP or domain for any MySQL server you want to import to.
The reason for the DROP command in the mysql prompt is to be sure we start with an empty and clean database.
Open the sql file and comment out the line that tries to create the existing database.
It sounds like your database dump includes the information for creating the database. So don't give the MySQL command line a database name. It will create the new database and switch to it to do the import.
If you create your database in direct admin or cpanel, you must edit your sql with notepad or notepad++ and change CREATE DATABASE command to CREATE DATABASE IF NOT EXISTS in line22
I create the database myself using the command line. Then try to import again, it works.