mysql client "use database name" taking too long to execute - mysql

My database contains large no of tables (more than 300 tables ) . when I execute " use database name " command on mysql command line client , its taking very long time to execute. Is there any way we can make it execute faster. ?

You can pass the -A argument to the mysql command-line tool to make it not load database metadata when using a database.
That being said, what you're describing is usually a sign that either you have too many tables and/or columns, or your database server is overloaded. Often, it's both. Either one should be fixed.

I know its very old post but thought of writing about it as i also had the same problem in past and found this all
you would be having this problem when using cli while connecting mysql remotely this problem generally doesn't occur on localhost. As while using "use" command mysql check metadata of table and for loading it, it confirms host and credentials while connecting to mysql cli remotely and may be that slows down select DB, you could skip dns resolving but i don't think that will solve the problem completely
Hence "-A" tag/attribute have to pass with mysql command on connect remotely which will not load metadata while selecting DB using "USE" command.
for an example :-
mysql -A -h HOST -u USER -p

Related

MySql tables disappeared and showing a table named as 'warning'

We were having a MySql Server running in Azure Windows Virtual Machine. We were not using it for the past 6 months. But recently we logged into the Virtual Machine and tried to access the database using MySql Work Bench. But it doesn't accept the password and we were unable to login. So we changed the root password by following the instructions from MySql documentation (Resetting the Root Password: Windows Systems).
Based on the instructions, the following commands were executed to reset the password:
CD C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld.exe
mysqld --no-defaults --datadir="C:\\ProgramData\\MySQL\\MySQL Server 5.7\\Data" --init-file=C:\\mysql-init.txt
After running the command, we were able to resect the password and logged into the Mysql as a Root user via the workbench. But, There were no tables other than tabled named as 'warning' in the databases. Following is the screenshot from the MySql Workbench. You can see the 'warning' tables is having four fields namely id, warning, Bitcoin_Address, and email. But there are no rows having values for these fields.
Is there anyone who knows what is exactly happened here? Any way to recover the missing tables? We were not having any other backup for these databases.
After 1 year 15 days. Most probably you have been hacked. I too had this issue in my raspberry pi server, which I used for the weather monitoring. But thanks don't have that important data to pay for it. Before coming to the conclusion check a few things.
How To Fix Corrupted Tables in MySQL, If not solved then,
log in to your mysql database in the terminal, query SHOW database, query USE database_name, query SHOW TABLES;
as mentioned, if you see only one table named WARNING,
Then, query CHECK TABLE `WARNING`;
In the displayed table, if you see under column Msg_text = OK
Then, query SELECT * FROM `WARNING`;
There you have your answer, A hacker has hacked your database, and is demanding money in bitcoin.
Solution: I don't trust them, they will not return your data. Best don't fall for the trap. Instead, use a strong password in your database, use ssh in your site (if you are using), use a python script to daily backup your database through CRON task.
Sorry, If you are a victim of a hacker. I cannot be of much help then.

When I try to log into MySQL via command line, keeps saying "unknown database 'magento2'"

When I try to log into MySQL via command line, keeps saying "unknown database 'magento2'"
Any ideas why? Tried as my username and root, getting the same message. If I can't log into mysql, how could I create a database to begin with of that name? So confused.
You should separate between your database application and a logical database. MySQL server is your database application / server.
When you're logging on to MySQL, you're choosing which logical database you would like to work with. A logical database is actually a container of objects such as tables, triggers, views, etc.
So when you see the error unknown database X, it's because you installed the MySQL server, but didn't create the logical database.
To see a list of all logical databases in your server, login to MySQL and run the command show databases;
To create your database, run the command create database magento2;
Now when you login to that database, it should be there and you can start creating your tables and query data from them.
I had the same issue and found that the database name was set in a cnf file. Perhaps you have something similar.

Update my remote MySQL database with my local MySQL database

I have a local Perl script that does a lot of parsing of web pages and then successfully updates my local MySQL database (WAMP server). I now want to send this local data to my remote server, but remotely connecting to my database isn't allowed with my hosting company. Unfortunately I never thought of that problem.
So, I now need to find an automated way to update my remote server (every 15mins). I mistakenly thought I could just edit my Perl script with the details of the remote server.
I am aware that I could use CGI or PHP to do the parsing on the server, but I really want to keep the parsing local for now.
Summary:
Local MySQL database -> remote MySQL database every 15mins ??
Any ideas what I can do?
Thanks :-)
if replication is not an option but you can still establish an ssh connection from local box to remote box, then
run mysqldump to export data into a file http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_where
scp file to remote box
mysql -u username -p password database_name < dumpfile.sql
If your server does not accept connections to mysql remotely you can create a ssh tunnel. Then you can apply the replication solution proposed by matcheek.
Here is a hint: http://realprogrammers.com/how_to/set_up_an_ssh_tunnel_with_putty.html
Based on the responses I've received, I think the answer to my original question is to stop using a cheap shared hosting company (no remote access to server, no cron jobs, etc) and start using a VPS hosting company. That will give me the freedom to remotely connect to my server, etc.
Thanks again to those who replied.
From how you described the problem replication seems to be the way to go
http://dev.mysql.com/doc/refman/4.1/en/replication-howto.html
Using a cron job could be another option. It would read file from your local machine and import data in the remote box.
I suggest the follwing:
On every local run, write the SQL statements (sans SELECT),
that you run against your copy of the DB also into a file
On your WAMP server create a small PHP script, gives back the oldest script from the first step (soem auth ofcourse)
On your remote server run a cronjob, that gets this from your local server and runs the SQL against the DB, then acknowledges it
On acknowledgement on your WAMP server, drop the file and give back the next one.
While this seems complicated, it allows for a restart after connectivity loss - something that I consider imposrtant.

Execute Shell command over MySql on remote host

Is it possible to login into a remote mysql machine and execute commands using 'system' on the remote machine.
I can log into the remote machine, but commands using: 'system' are executed at my local machine.
Thanks indeed!
I using mysql to connect from 'Host1' to 'Host2' using the command
mysql -uUsername -p data_base_name -h Host2
When I execute
'system hostname'
after I'm connected i get.
'Host1'
I cannot log into my remote host using ssh. I don't know why. I need to do some log analysis and the only option I have is to connect to that machine using mysql. I can connect to that machine! –
As far as I know, this is definitely not possible. It's far beyond the scope of mySQL, and there would be immense security implications if it were.
I don't think there is an alternative to getting SSH (or some other service that might help) running again.
Consider doing a select into outfile and writing script code into a place that will be executed on the server. For example, if mysql is running as root on the server, you be able to add something to the /etc/rc2.d which will get executed on the server during boot time.
Alternatively, if there is a file which is used as a source for scheduling tasks you may be able to overwrite that again using "select into outfile."
system runs local commands on your box. If you need to do anything with logs, either contact your hoster, to provide a way to download them or access them.

How to upload 10 Gb of data to MySQL programmatically without crashing like on PHPMyAdmin?

I'm very surprised that it seems impossible to upload more than a few megabytes of data to mysql database through PHPMyAdmin whereas I can upload a msaccess table easily up to 2 Gigabytes.
So is there any script in php or anything that can allow to do so unlike phpmyadmin ?
PhpMyAdmin is based on HTML and PHP. Both technologies were not built and never intended to handle such amounts of data.
The usual way to go about this would be transferring the file to the remote server - for example using a protocol like (S)FTP, SSH, a Samba share or whatever - and then import it locally using the mysql command:
mysql -u username -p -h localhost databasename < infile.sql
another very fast way to exchange data between two servers with the same mySQL version (it doesn't dump and re-import the data but copies the data directories directly) is mysqlhotcopy. It runs on Unix/Linux and Netware based servers only, though.
No. Use the command line client.
mysql -hdb.example.com -udbuser -p < fingbigquery.sql