Why not Enable / configure mySQL Replication Service? I am not pro at it but I know you can achieve that by using mySQL Replication. See the link for details.
http://dev.mysql.com/doc/refman/5.0/en/replication.html
I am updating my answer here try to guide you to the proper sources or techniques. Try enabling clustering. and try to go through this link to load balance your mySql instances.
https://severalnines.com/resources/tutorials/mysql-load-balancing-haproxy-tutorial
one machine running mySql instance and the same one doing the backup will not solve your issue but can be achieved through virtualization. Consider vmWare for example or try Virtualbox too.. but again if your server fails you will not going have nay means to take advantage of such design. However what will be good you go for another box and deploy the sql node there and then enable/ configure clustering
I was using one of two ways to get a random row:
SELECT * FROM mytable ORDER BY RANDOM();
and
SELECT * FROM mytable LIMIT 1 OFFSET <random number>;
The offset method was faster for low offset numbers, otherwise super slow. An offset of 1 million took ~600 msec, while 100 million was 60 seconds (average query time for midpoint offset was 2.5 minutes). For order by random, all queries were ~5 minutes.
I ended up finding a good solution, similar to Mat's comment, but I don't need to keep track of how many rows there are.
I added an integer column called "randval" with a btree index. When a record is saved, I generate a random number between 1 and 2 billion. It took a while to migrate existing data (about half a day on slow hardware), but now random selects are super fast, typically around 1 millisecond using this query:
SELECT * FROM mytable WHERE randval >= <random number> ORDER BY randval LIMIT 1;
With 500 million rows, not every random number has a value, so the order by with limit gives us the next closest one and the index makes it quick, with a 150,000x speedup for what was an average 2.5-minute query.
Databases don't like doing random things, but they sure do well at specific things that just happen to have random values.
Best Answer
Reference: https://docs.microsoft.com/en-us/sql/tools/sqlcmd-utility
With
-q
you can execute multiple query, as you do not get your prompt back until you hitctrl+c
.This is in my workstation.
of
-q
.