• Useful MySQL Commands

    There are a lot of usefully MySQL commands that I either don’t run enough to remember or just end up using some GUI to accomplish. Nothing against Navicat, but what kind of sysadmin would I be if I couldn’t do it at the command line as well. Anyhow, I had to do a bunch of this kind of work lately, so I thought I would write the more common commands down here so I would have them to reference.

    It is generally a good idea to firewall off your MySQL port (3306) unless you are on a secure network. The downside to this is that it prevents you from using GUI tools like Navicat to connect to your database server. No problem, just use this command to SSH tunnel a connection. After doing this, you can connect to your database on localhost port 8888:

    ssh -fNg -L 8888:127.0.0.1:3306 login@mysql-server

    Once you have installed a new instance of MySQL, you have to change the root password:

    # mysql -u root
    mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpwd');
    mysql> SET PASSWORD FOR 'root'@'yourhostname' = PASSWORD('newpwd');
    mysql> exit

    Depending on the way you handle your MySQL installation, you will most likely have to run the mysql_upgrade script after upgrades to use all the new features:

    mysql_upgrade -u root –password=yourpassword

    Do a thorough check to see if your tables are corrupted:

    mysqlcheck -u root -p --check --extended --all-databases

    Repair any corruption if it exists:

    mysqlcheck -u root -p --repair --all-databases

    Look at all your tables and optomize them if necessary:

    mysqlcheck -u root -p --optimize --all-databases

    This entry was posted on Thursday, April 30th, 2009 at 10:45 pm and is filed under Data and Technology. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
  • 0 Comments

    Take a look at some of the responses we've had to this article.

  • Leave a Reply

    Let us know what you thought.

  • Name (required):

    Email (required):

    Website:

    Message:

Visitors have tagged this post: mysql commands (184) - ssh mysql commands (49) - mysql ssh commands (36) - mysql command list (29) - mysql commands list (25) - mysql u root p password (17) - mysqlcheck command (15) - mysqlcheck optimize (13) - mysql repair command (13) - mysql login command (12) - check mysql port (12) - mysql connect command (11) - ssh mysql command (11) - basic mysql commands (10) - mysql 4 commands (10) - mysql check port (10) - mysql set command (10) - common mysql commands (8) - how to check mysql port (7) - mysql ssh command (7) - mysql commands ssh (7) - ssh mysql version (6) - mysqlcheck commands (6) - mysql check connections (6) - mysql optimize command (5) - all mysql commands (5) - mysql commends (5) - mysql commonds (5) - login mysql command (5) - checking mysql port (5) - mysql password command (5) - SSH mysql optimize (5) - myswl commands (4) - ssh list databases (4) - mysqlcheck repair database command (4) - mysql command port (4) - repair command in mysql (4) - mysql check connection (4) - mysql mysqlcheck (4) - mysql (4) - mysql u root p mysql REPAIR (4) - ssh commands mysql (4) - repair mysql ssh (4) - mysql command line repair database (4) - mysql change password command (3) - repair table via ssh (3) - SSH mysql check (3) - all commands in mysql (3) - set command in mysql (3) - mysql command line change root password (3) - repair database ssh (3) - mysql repair commands (3) - mysql login commands (3) - SET PASSWORD FOR \'root\'@\'yourhostname\ = PASSWORD(\'yourpassword\'); (3) - repair mysql root password (3) - list mysql tables ssh (3) - mysql4 commands (3) - OPTIMIZE mysql command (3) - solaris mysql commands (3) - mysql repair database command line (3) - ssh mysql view tables (3) - repair mysql command (3) - mysql root commands (3) - mysql copmmand list tables (3) - repair password mysql (3) - mysql checking commands (3) - common cmds similar to oracle in mysql (3) - SSH check mySQL version (3) - mysql command .net (3) - mysql commands login (3) - mysqlcheck ssh (3) - optimize mysql ssh (3) - ssh mysql repair all tables (3) - mysql command repair database (3) - loop mysql command (3) - mysql common commands (3) - repair mysql table SSH (3) - mysql root connection (3) - common commands in mysql (3) - list mysql database ssh (2) - command MySQL Password check (2) - mysql commands -h (2) - mysql ssh list users (2) - mysql command list databases (2) - command to list all tables sizes in a Mysql database (2) - ssh command to repair mysql database (2) - mysql login different port (2) - common mysql port (2) - ssh list mysql databases (2) - mysql \"repair all tables\ (2) - executing mysql command in ssh (2) - repair mysql dbs using ssh (2) - mysql version ssh (2) - mysql command line change password without root (2) - mysql connect root password (2) - my sql commands (2) - mysql 4 command (2) - mysql login command port (2) - mysql change port (2) - how to run command mysqlcheck (2) - How to repair MySQL table from SSH (2) - command mysql version (2) - mysql connect command port (2) - MySQL 5 commands (2) - mysql command line open port (2) - how to optimize mysql databases using mysqlcheck (2) - ssh copy mysql tables (2) - ssh mysqlcheck (2) - Mysql commandline repair (2) - optimize mysql database ssh (2) - mysqlcheck password (2) - SHH mysql commands (2) - ssh repair mysql database (2) - Mysql commands in solaris (2) - repair database mysql ssh (2) - mysql commands list using ssh (2) - mysql check commands (2) - ssh repair mysql (2) - mysql change root password using gui (2) - ssh fNg commands (2) - mysql 5 commands run script (2) - repair command mysql (2) - command check mysql version (2) - mysql commands foreach (2) - check mysql connection -php (2) - check mysql password (2) - command what port mysql using (2) - repair mysql from ssh (2) - repair mysql database command (2) - mysql connect root (2) - mysql connect as root (2) - set command mysql (2) - mysql commnad for view (2) - mysqlcheck repair (2) - check mysql connection (2) - ssh mysql (2) - mysql ssh commande (2) - mysql port command (2) - mysql commands repair (2) - how to update mysql user password in ssh (2) - ssh repair all database (2) - mysql change port cmd (2) - mysql check command (2) - ssh command to check mysql version (2) - mysql command check (2) - ssh mysql repair a database table (2) - view mysql tables in ssh (2) - mysql command linecheck if db exists (2) - login root pass root tunnel (2) - ssh mysql commands list (2) -