Why is MySQLSlap giving me additional prompt instead of running? - mysql

I am trying to benchmark some queries using mysqlslap. I've never used it before. I am trying to follow some tutorials and am trying to run a simple command to get a hang of how it works like from this tutorial.
When I run the command mysqlslap --concurrency=20 --iterations=4 --query="sELCT * FROM listusers;" --create-schema=my_database instead of actually testing and returning some metrics, I just get another prompt like
I have tried this command with username and password fields as well with the same results.
What is this prompt and how do I get the command to actually run the metrics?

mysqlslap is not a MySQL command, but a separate binary tool.
So instead of trying to use it inside mysql console, use it directly in bash/shell.

Related

MYSQL Optimize Statement

I am trying to use the optimize statement on the Shell of the MYSQL system and have tried using
mysqlcheck -o --all-databases;
mysqlcheck -o <databasename>;
However, it does not work and showed me an error,
Is there any other command that could make it work? I am running the script on xampp shell for mysql and would like to just check the optimization for the table. I know that there would errors for it however I would like to view it.
mysqlcheck is a command to give to the OS via its "shell". It is not a command to use inside the "commandline tool" mysql; that would be OPTIMIZE TABLE as mentioned in a Comment.
But... Why do you think you want to Optimize all the tables. While the name "optimize" is tempting, it is rarely worth bothering with.

Running thousands of MySQL queries via putty

Every time I try to run more than a few insert into queries on my ubunutu mysql database via putty I get errors from one or more rows that fail to update, and if it's hundreds or more, it usually crashes or is pauses from an incomplete query presumably. This has nothing to do with the syntax of the queries as when I run them individually they run fine. I there anything I can do to run fix this?
I've tried Rocket's solution but it did much the same thing (skipping rows and then hangs).
I've just noticed there are carriage returns and line feeds in the data so after removing those it seems to be working wihtout any errors but is taking absolutely ages using the BEGIN, COMMIT method. Maybe because it is only parsing one single really long line now instead of several lines at a time.
I'm copying and pasting queries from an excel spreadsheet onto the mysql command line in putty. Putty is connected the whole time. It's tricky to debug as putty puts a limit to the number of lines it displays. – garry 45 mins ago
Don't do this. Putty will drop parts of the content you paste, or place length limits on it.
Instead:
Export the queries from Excel into a text file on your PC, for example "exported_queries.sql".
Transfer that text file to your Ubuntu server, using scp.
Then open an ssh session to the Ubuntu server, and run the text file as input to the mysql program. You can do this with the source command in the mysql shell:
mysql> source exported_queries.sql
I also recommend running tmux or screen in your Ubuntu ssh window, because those programs are good for keeping your session alive even if Putty disconnects. If you have a long-running command in your ssh session, you can reconnect and "reattach" to the session in progress.

MySQL: How to import a sql dump.. inside mysql command line?

I often keep a shell open to a remote server where I'm spending a lot of time in mysql. Exiting mysql and logging back in seems like a pain I shouldn't have to deal with if I just want to run a sql file.
When I'm running MySql from the command line, how can I run a dump file?
Right now, I'm using the same approach outlined in this post.
mysql> use db_name;
mysql> source backup-file.sql;
You may want to take a look at this answer: https://stackoverflow.com/a/17666285

What is a mysql disconnect command line (why is it useful)?

I am running a mysql database and I connect to it just fine. My question is: whenever I connect to the database (to add new input via php) do I also have to include a disconnect command line?
I ask because my bandwidth usage is growing faster than I expected so I am happy thinking that I am getting traffic, but perhaps it is growing because I connect and do not "disconnect"?
From the mysql docs
mysql is a simple SQL shell with input line editing capabilities. It
supports interactive and noninteractive use.
The fact is that the SQL shell should not be causing major load on your box. The standard practice is to just close the shell and kill the program.
Typing Control+C causes mysql to attempt to kill the current
statement. If this cannot be done, or Control+C is typed again before
the statement is killed, mysql exits
When you exit mysql command line tool the process will end and mysql will continue doing its thing. But the answer to your question is no SQL shell should not be slowing things.
From PHP its a good idea to close the connection when you are done using it. To check out what processes are running open up mysql cmd tool and try the following to see what is connected to your mysql instance.
SHOW PROCESSLIST
if showprocesslist isnt what you were looking for give this a shot:
mysql > show status like '%onn%';
Hopefully this will give you enough information to handle the traffic load.
devzone.zend.com :
"Open connections (and similar resources) are automatically destroyed at the end of script execution. However, you should still close or free all connections, result sets and statement handles as soon as they are no longer required. This will help return resources to PHP and MySQL faster."
My advice:
It is a good practise to close a connection after doing the queries you wanted.

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

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