{"id":18,"date":"2004-12-29T23:04:50","date_gmt":"2004-12-30T07:04:50","guid":{"rendered":"http:\/\/hongyu.org\/wordpress\/?p=18"},"modified":"2020-04-11T19:58:49","modified_gmt":"2020-04-12T02:58:49","slug":"mysql","status":"publish","type":"post","link":"https:\/\/www.hongyu.org\/wordpress\/?p=18","title":{"rendered":"MySQL most used commands"},"content":{"rendered":"<p>Started with system database of mysql<\/p>\n<p><code>$ mysql -uroot -ppassword mysql<\/code><\/p>\n<p>Create a database:<br \/>\n<code><br \/>\nmysql&gt; CREATE database mydb<br \/>\nmysql&gt; drop database mydb;<br \/>\nmysql&gt; show databases;<br \/>\n<\/code><\/p>\n<p>Corresponding Unix system command<br \/>\n<code><br \/>\n$ mysqladmin drop mydb<br \/>\n$ mysqlshow<br \/>\n<\/code><\/p>\n<p>To add password<br \/>\n<code><br \/>\n$ mysqladmin password xxxx<br \/>\n<\/code><\/p>\n<p>To export database<br \/>\n<code><br \/>\n$ mysqldump -u myuser -pmypass mydb &gt; exl.sql<br \/>\n<\/code><\/p>\n<p>To add a user to a database:<br \/>\n<code><br \/>\nmysql&gt; GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP on mydb.* to 'myuser'@'localhost' IDENTIFIED BY 'mypassword';<br \/>\n<\/code><br \/>\nor<br \/>\n<code><br \/>\nmysql&gt; INSERT INTO user (Host,User,Password) VALUES('localhost','dummy','mypassword');<br \/>\n<\/code><\/p>\n<p>To add a user that can access from other client machines, use % as the host<br \/>\n<code><br \/>\nmysql&gt; GRANT SELECT on db1.* to 'myuser'@'%' IDENTIFIED BY 'mypassword';<br \/>\n<\/code><\/p>\n<p>To change password, use<br \/>\n<code><br \/>\nmysql&gt; update user set password=PASSWORD(\u00e2\u20ac\u0153NEW-PASSWORD\u00e2\u20ac\u009d) where User=\u00e2\u20ac\u2122myuser\u00e2\u20ac\u2122;<br \/>\n<\/code><\/p>\n<p>To change permissions, use<br \/>\n<code><br \/>\nmysql&gt; GRANT USAGE ON *.* TO 'dummy'@'localhost';<br \/>\nmysql&gt; GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP on mydb.* to myuser;<br \/>\n<\/code><\/p>\n<p>or<br \/>\n<code><br \/>\nmysql&gt; GRANT ALL on mydb.* to myuser<br \/>\nmysql&gt; FLUSH PRIVILEGES;<br \/>\n<\/code><\/p>\n<p>&#8212; special for loading file<br \/>\n<code><br \/>\nmysql&gt; GRANT FILE on *.* to myuser<br \/>\nmysql&gt; LOAD DATA INFILE '\/mypath\/myfile' INTO TABLE mytable FIELDS TERMINATED BY '\\t' LINES TERMINATED BY '\\n';<br \/>\n<\/code><\/p>\n<p>To check the error such as the infamous &#8220;ERROR 1005 (HY000)&#8221;, use<br \/>\n<code><br \/>\nmysql&gt; SHOW ENGINE INNODB STATUS<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Started with system database of mysql $ mysql -uroot -ppassword mysql Create a database: mysql&gt; CREATE database mydb mysql&gt; drop database mydb; mysql&gt; show databases; Corresponding Unix system command $ mysqladmin drop mydb $ mysqlshow To add password $ mysqladmin password xxxx To export database $ mysqldump -u myuser -pmypass mydb &gt; exl.sql To add &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.hongyu.org\/wordpress\/?p=18\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;MySQL most used commands&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/18"}],"collection":[{"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=18"}],"version-history":[{"count":16,"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/18\/revisions"}],"predecessor-version":[{"id":485,"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/18\/revisions\/485"}],"wp:attachment":[{"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=18"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=18"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=18"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}