Created
October 14, 2011 20:20
-
-
Save raster/1288219 to your computer and use it in GitHub Desktop.
MySQL tricks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Login as someuser (type password at prompt): | |
mysql -u someuser -p | |
(To not be promted for the password, you would use 'mysql -u someuser -ppassword') | |
Load a database from a dump file: | |
mysql -u someuser -p dbname < somedatabase.mysql | |
Dump a database to a file: | |
mysqldump -u someuser -p somedatabase >somedatabase.sql | |
Dump specified tables of a database to a file: | |
mysqldump -u someuser -p somedatabase --tables specific_table >somedatabasetable.sql | |
Output a SQL query to a file: | |
echo "select * from title where new = \"No\"" | mysql -u someusername -psomepassword somedatabase >./outputfile.txt; | |
From within mysql: | |
Grant privs to someuser on the local box: | |
GRANT ALL PRIVILEGES ON dbname.* TO someuser@localhost IDENTIFIED BY 'password' WITH GRANT OPTION; | |
Grant select only privs to remoteuser on another box: | |
GRANT SELECT ON dbname.* TO remoteuser@remotehost IDENTIFIED BY 'password'; | |
Adding a column to a table: | |
ALTER TABLE foo ADD COLUMN fubar varchar(255) AFTER baz; | |
Adding an index to a table: | |
ALTER TABLE px_items ADD INDEX (fubar); | |
Copying a table: | |
CREATE TABLE new_table SELECT * FROM orig_table; | |
Fixing the 'old client' problem: | |
UPDATE mysql.user SET Password = OLD_PASSWORD('newpwd') WHERE Host = 'some_host' AND User = 'some_user'; | |
FLUSH PRIVILEGES; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment