MindDump. Photos. And random ramblings.

Expandmenu Shrunk


  • Tag Archives MySQL
  • MySQL Linux CLI command execution

    As another aid to my memory, you can run mysql commands on the command line like this:

    mysql -u user -p[password] database -e "SELECT * FROM orders;".

     

    You can also send the mysql client commands on stdin:

    echo "SELECT * FROM orders" | mysql -u user -p[password] database

     

    Or read them in with a file redirection

    mysql -u user -p[password] database < /home/kirrus/orders.sql

    That last one is really handy for reading MySQL dumps back into MySQL.


  • MySQL GRANT syntax oddity, show views

    So that I don’t forget: Despite what the documentation says, being unclear (links always have an underscore over there, so it’s hard to tell difference between a linked underscore linked item, and one merely space-separated), you should grant ‘SHOW VIEW’, not ‘SHOW_VIEW’. Additionally, ‘SHOW VIEW’ really needs SELECT permissions as well.


  • Notes / MySQL Transactions

    Why should you not use your notepad as a coaster? This is why:

    Notes
    The notes did say this, before my lovely hot black coffee destroyed them:

    “begin” == Start transaction
    “commit” == End transaction, saving all changes
    “rollback” == Undo all changes that you’ve made in the transaction

    What are they? In mySQL 5, with a table storage type of “innodb” you can use transactions. This means, that you can make a set of changes together, like recording the removal of a credit, and the adding of an advert to a website, at one instance, even if it’s multiple mysql transactions within one connection.

    You do that, by sending the command (literally “BEGIN;” or “begin;”) to start a transaction, run all the queries you need to run, and then run the commit if you want the all the changes to take, or rollback if you don’t. If any one of the sql queries fails after you’ve made a begin, and it shouldn’t have, you can rollback *all* the changes you’ve made to the database. Obviously, this needs one mySQL connection, but if you’re using more than one each run of the program you’re using, I’d be very surprised.