{"id":92,"date":"2023-02-25T20:35:26","date_gmt":"2023-02-25T12:35:26","guid":{"rendered":"https:\/\/www.road-trip.cc\/?p=92"},"modified":"2024-05-06T16:04:03","modified_gmt":"2024-05-06T08:04:03","slug":"mysql%e5%b8%b8%e7%94%a8%e5%91%bd%e4%bb%a4","status":"publish","type":"post","link":"https:\/\/www.road-trip.cc\/?p=92","title":{"rendered":"MySQL\u5e38\u7528\u547d\u4ee4"},"content":{"rendered":"\n<pre class=\"wp-block-code has-base-background-color has-background\"><code>-- Creates the new database\nmysql&gt; create database db_example;\n\n-- Drop the database\nmysql&gt; drop database db_example;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>-- Creates the user\n-- % \u4ee3\u8868\u53ef\u4ee5\u4ece\u4efb\u4f55\u673a\u5668\u8bbf\u95ee\u8be5\u6570\u636e\u5e93\nmysql&gt; create user 'USER'@'%' identified by 'PASSWORD';\n\n-- Gives all privileges to the new user on the newly created database\nmysql&gt; grant all on db_example.* to 'USER'@'%';\n\n-- Revokes all the privileges from the user\nmysql&gt; revoke all on db_example.* from 'springuser'@'%';\n\n-- Grant the minimum privileges \nmysql&gt; grant select, insert, delete, update on db_example.* to 'springuser'@'%';\n\n-- List all database users\nmysql&gt; select user from mysql.user;\n\n-- Modify user's password\n-- Mysql 8.0\u4ee5\u4e0a\u5bc6\u7801\u7b56\u7565\u9650\u5236\u5fc5\u987b\u8981\u5927\u5c0f\u5199\u52a0\u6570\u5b57\u7279\u6b8a\u7b26\u53f7\uff0c\u5426\u5219\u4f1a\u62a5\u9519\nmysql&gt; alter user 'USER'@'%' IDENTIFIED BY 'NEW-PASSWORD';<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>-- List all tables\nmysql&gt; show tables;\n\n-- List specific tables\nmysql&gt; show tables like \"%keyword%\";\n\n-- Show table create schema\nmysql&gt; show create table table_name;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u67e5\u770b\u67d0\u4e00\u4e2a\u8868\u4f7f\u7528\u7684\u5b58\u50a8\u7a7a\u95f4\u5927\u5c0f\nselect\n    table_schema as '\u6570\u636e\u5e93',\n    table_name as '\u8868\u540d',\n    table_rows as '\u8bb0\u5f55\u6570',\n    truncate(data_length\/1024\/1024, 2) as '\u6570\u636e\u5bb9\u91cf(MB)',  truncate(index_length\/1024\/1024, 2) as '\u7d22\u5f15\u5bb9\u91cf(MB)'\nfrom \n    information_schema.tables\nwhere\n    table_name='sign_name'\norder by\n    data_length desc, index_length desc;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u67e5\u770b\u67d0\u4e00\u4e2a\u6570\u636e\u5e93\u7684\u6240\u6709\u8868\u4f7f\u7528\u7684\u5b58\u50a8\u7a7a\u95f4\u5927\u5c0f\nselect\n    table_schema as '\u6570\u636e\u5e93',\n    table_name as '\u8868\u540d',\n    table_rows as '\u8bb0\u5f55\u6570',\n    truncate(data_length\/1024\/1024, 2) as '\u6570\u636e\u5bb9\u91cf(MB)',  truncate(index_length\/1024\/1024, 2) as '\u7d22\u5f15\u5bb9\u91cf(MB)'\nfrom \n    information_schema.tables\nwhere\n    table_schema ='sms'\norder by\n    data_length desc, index_length desc;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u67e5\u770b\u6240\u6709\u8868\u4f7f\u7528\u7684\u5b58\u50a8\u7a7a\u95f4\u5927\u5c0f\nselect\n    table_schema as '\u6570\u636e\u5e93',\n    table_name as '\u8868\u540d',\n    table_rows as '\u8bb0\u5f55\u6570',\n    truncate(data_length\/1024\/1024, 2) as '\u6570\u636e\u5bb9\u91cf(MB)',  truncate(index_length\/1024\/1024, 2) as '\u7d22\u5f15\u5bb9\u91cf(MB)'\nfrom \n    information_schema.tables\norder by\n    data_length desc, index_length desc;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>-- date\u548c\u65f6\u95f4\u6233\u4e92\u8f6c\n-- unix_timestamp(): date\u8f6c\u65f6\u95f4\u6233\n-- from_unixtime(): \u65f6\u95f4\u6233\u8f6cdate\nmysql&gt; select send_time , from_unixtime(unix_timestamp(send_time)) from sms_record sr limit 1; <\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u521b\u5efa\u7d22\u5f15\nmysql> ALTER TABLE tableName ADD INDEX indexName(columnName);\nmysql> show index from tableName;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[34,41],"class_list":["post-92","post","type-post","status-publish","format-standard","hentry","category-7","tag-devops","tag-mysql"],"_links":{"self":[{"href":"https:\/\/www.road-trip.cc\/index.php?rest_route=\/wp\/v2\/posts\/92","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.road-trip.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.road-trip.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.road-trip.cc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.road-trip.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=92"}],"version-history":[{"count":3,"href":"https:\/\/www.road-trip.cc\/index.php?rest_route=\/wp\/v2\/posts\/92\/revisions"}],"predecessor-version":[{"id":209,"href":"https:\/\/www.road-trip.cc\/index.php?rest_route=\/wp\/v2\/posts\/92\/revisions\/209"}],"wp:attachment":[{"href":"https:\/\/www.road-trip.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=92"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.road-trip.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=92"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.road-trip.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=92"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}