<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tianzhou</title>
    <description>The latest articles on DEV Community by Tianzhou (@tianzhou).</description>
    <link>https://dev.to/tianzhou</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F425815%2Fd1e0794f-72e2-453d-9693-9770b28d78c6.png</url>
      <title>DEV Community: Tianzhou</title>
      <link>https://dev.to/tianzhou</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tianzhou"/>
    <language>en</language>
    <item>
      <title>🚀Top mysql Commands with Examples🦄</title>
      <dc:creator>Tianzhou</dc:creator>
      <pubDate>Mon, 25 Sep 2023 06:26:12 +0000</pubDate>
      <link>https://dev.to/bytebase/top-mysql-commands-with-examples-547b</link>
      <guid>https://dev.to/bytebase/top-mysql-commands-with-examples-547b</guid>
      <description>&lt;p&gt;MySQL is the world's most popular open-source relational database management system that uses SQL to manage data.&lt;br&gt;
It's known for its scalability, reliability, and ease of use.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mysql&lt;/code&gt; is the official CLI client to command the MySQL database. It supports interactive and noninteractive use.&lt;/p&gt;

&lt;p&gt;Below we list the 10 most commonly used &lt;code&gt;mysql&lt;/code&gt; commands with examples.&lt;/p&gt;
&lt;h2&gt;
  
  
  1. Connect to a database - mysql -u xxx -p -h xxx -P xxx db
&lt;/h2&gt;

&lt;p&gt;Connects to the local MySQL server via socket /tmp/mysql.sock as the specified user and prompts for a password.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mysql &lt;span class="nt"&gt;-u&lt;/span&gt; username &lt;span class="nt"&gt;-p&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Connects to the MySQL server on the specified host at port 3306 and prompts for a password.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mysql &lt;span class="nt"&gt;-u&lt;/span&gt; username &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="nt"&gt;-h&lt;/span&gt; &lt;span class="nb"&gt;hostname&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Connects to the MySQL server on the specified host and port and prompts for a password.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mysql &lt;span class="nt"&gt;-u&lt;/span&gt; username &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="nt"&gt;-h&lt;/span&gt; &lt;span class="nb"&gt;hostname&lt;/span&gt; &lt;span class="nt"&gt;-P&lt;/span&gt; portnumber
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Connects to the specified database on the specified host and port as the specified user and prompts for a password.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mysql &lt;span class="nt"&gt;-u&lt;/span&gt; username &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="nt"&gt;-h&lt;/span&gt; &lt;span class="nb"&gt;hostname&lt;/span&gt; &lt;span class="nt"&gt;-P&lt;/span&gt; portnumber &lt;span class="nt"&gt;-D&lt;/span&gt; databasename
&lt;span class="c"&gt;# can also omit -D&lt;/span&gt;
mysql &lt;span class="nt"&gt;-u&lt;/span&gt; username &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="nt"&gt;-h&lt;/span&gt; &lt;span class="nb"&gt;hostname&lt;/span&gt; &lt;span class="nt"&gt;-P&lt;/span&gt; portnumber databasename
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Run a single command - mysql -e
&lt;/h2&gt;

&lt;p&gt;Use &lt;code&gt;-e&lt;/code&gt; to execute a single statement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mysql &lt;span class="nt"&gt;-u&lt;/span&gt; username &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="nt"&gt;-h&lt;/span&gt; &lt;span class="nb"&gt;hostname&lt;/span&gt; &lt;span class="nt"&gt;-P&lt;/span&gt; portnumber databasename &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"SELECT 1"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alternatively, you can pipe the statements from a file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mysql &lt;span class="nt"&gt;-u&lt;/span&gt; username &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="nt"&gt;-h&lt;/span&gt; &lt;span class="nb"&gt;hostname&lt;/span&gt; &lt;span class="nt"&gt;-P&lt;/span&gt; portnumber databasename &amp;lt; filename.sql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. List all databases - SHOW DATABASES
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mysql&amp;gt; SHOW DATABASES&lt;span class="p"&gt;;&lt;/span&gt;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Support LIKE&lt;/span&gt;
mysql&amp;gt; SHOW DATABASES LIKE &lt;span class="s1"&gt;'%schema'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
+--------------------+
| Database &lt;span class="o"&gt;(&lt;/span&gt;%schema&lt;span class="o"&gt;)&lt;/span&gt; |
+--------------------+
| information_schema |
| performance_schema |
+--------------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Switch to another database - USE xxx
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mysql&amp;gt; USE mysql&lt;span class="p"&gt;;&lt;/span&gt;
Reading table information &lt;span class="k"&gt;for &lt;/span&gt;completion of table and column names
You can turn off this feature to get a quicker startup with &lt;span class="nt"&gt;-A&lt;/span&gt;

Database changed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. List all tables under a database - SHOW TABLES
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Support LIKE&lt;/span&gt;
mysql&amp;gt; SHOW TABLES LIKE &lt;span class="s1"&gt;'time%'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
+---------------------------+
| Tables_in_mysql &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;time&lt;/span&gt;%&lt;span class="o"&gt;)&lt;/span&gt;   |
+---------------------------+
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
+---------------------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6. Describe table schema - DESCRIBE xxx
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mysql&amp;gt; DESCRIBE time_zone&lt;span class="p"&gt;;&lt;/span&gt;
+------------------+---------------+------+-----+---------+----------------+
| Field            | Type          | Null | Key | Default | Extra          |
+------------------+---------------+------+-----+---------+----------------+
| Time_zone_id     | int unsigned  | NO   | PRI | NULL    | auto_increment |
| Use_leap_seconds | enum&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y'&lt;/span&gt;,&lt;span class="s1"&gt;'N'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; | NO   |     | N       |                |
+------------------+---------------+------+-----+---------+----------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# DESC also works&lt;/span&gt;
mysql&amp;gt; DESC time_zone&lt;span class="p"&gt;;&lt;/span&gt;
+------------------+---------------+------+-----+---------+----------------+
| Field            | Type          | Null | Key | Default | Extra          |
+------------------+---------------+------+-----+---------+----------------+
| Time_zone_id     | int unsigned  | NO   | PRI | NULL    | auto_increment |
| Use_leap_seconds | enum&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y'&lt;/span&gt;,&lt;span class="s1"&gt;'N'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; | NO   |     | N       |                |
+------------------+---------------+------+-----+---------+----------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  7. List user and grants - SHOW GRANTS;
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;SHOW GRANTS&lt;br&gt;
    [FOR user_or_role&lt;br&gt;
        [USING role [, role] ...]]&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Show grants for the current user&lt;/span&gt;
mysql&amp;gt; SHOW GRANTS&lt;span class="p"&gt;;&lt;/span&gt;
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Grants &lt;span class="k"&gt;for &lt;/span&gt;root@%                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON &lt;span class="k"&gt;*&lt;/span&gt;.&lt;span class="k"&gt;*&lt;/span&gt; TO &lt;span class="sb"&gt;`&lt;/span&gt;root&lt;span class="sb"&gt;`&lt;/span&gt;@&lt;span class="sb"&gt;`&lt;/span&gt;%&lt;span class="sb"&gt;`&lt;/span&gt; WITH GRANT OPTION                                                                                                                                                                                                                                                                                                                                                                 |
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Show grants for a particular user&lt;/span&gt;
mysql&amp;gt; SHOW GRANTS FOR root@localhost&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# List all users and grants&lt;/span&gt;
mysql&amp;gt; SELECT User, Host, Grant_priv, Super_priv FROM mysql.user&lt;span class="p"&gt;;&lt;/span&gt;
+------------------+-----------+------------+------------+
| User             | Host      | Grant_priv | Super_priv |
+------------------+-----------+------------+------------+
| root             | %         | Y          | Y          |
| healthchecker    | localhost | N          | N          |
| mysql.infoschema | localhost | N          | N          |
| mysql.session    | localhost | N          | Y          |
| mysql.sys        | localhost | N          | N          |
| root             | localhost | Y          | Y          |
+------------------+-----------+------------+------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  8. Show connections - SHOW PROCESSLIST
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;SHOW [FULL] PROCESSLIST&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Without the FULL keyword, SHOW PROCESSLIST displays only the first 100 characters of each statement in the Info field.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mysql&amp;gt; SHOW PROCESSLIST&lt;span class="p"&gt;;&lt;/span&gt;
+-------+-----------------+------------------+------+---------+--------+------------------------+-------------------+
| Id    | User            | Host             | db   | Command | Time   | State                  | Info              |
+-------+-----------------+------------------+------+---------+--------+------------------------+-------------------+
|     5 | event_scheduler | localhost        | NULL | Daemon  | 696323 | Waiting on empty queue | NULL              |
| 21238 | root            | 172.17.0.1:41440 | NULL | Query   |      5 | User &lt;span class="nb"&gt;sleep&lt;/span&gt;             | SELECT SLEEP&lt;span class="o"&gt;(&lt;/span&gt;100&lt;span class="o"&gt;)&lt;/span&gt; |
| 21239 | root            | 172.17.0.1:41448 | NULL | Query   |      0 | init                   | SHOW PROCESSLIST  |
+-------+-----------------+------------------+------+---------+--------+------------------------+-------------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to apply filtering, then query the underlying &lt;code&gt;INFORMATION_SCHEMA.PROCESSLIST&lt;/code&gt; table.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mysql&amp;gt; SELECT &lt;span class="k"&gt;*&lt;/span&gt; FROM INFORMATION_SCHEMA.PROCESSLIST WHERE USER &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'root'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
+-------+------+------------------+------+---------+------+------------+------------------------------------------------------------------+
| ID    | USER | HOST             | DB   | COMMAND | TIME | STATE      | INFO                                                             |
+-------+------+------------------+------+---------+------+------------+------------------------------------------------------------------+
| 21238 | root | 172.17.0.1:41440 | NULL | Query   |    2 | User &lt;span class="nb"&gt;sleep&lt;/span&gt; | SELECT SLEEP&lt;span class="o"&gt;(&lt;/span&gt;100&lt;span class="o"&gt;)&lt;/span&gt;                                                |
| 21239 | root | 172.17.0.1:41448 | NULL | Query   |    0 | executing  | SELECT &lt;span class="k"&gt;*&lt;/span&gt; FROM INFORMATION_SCHEMA.PROCESSLIST WHERE USER &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'root'&lt;/span&gt; |
+-------+------+------------------+------+---------+------+------------+------------------------------------------------------------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  9. Kill connection - KILL
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;KILL [CONNECTION | QUERY] processlist_id&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;KILL CONNECTION&lt;/code&gt; is the same as KILL with no modifier: It terminates the connection associated with the given processlist_id, after terminating any statement the connection is executing. This can be useful if you want to terminate a long-running or problematic connection that is causing issues for other users or processes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mysql&amp;gt; KILL 123&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;KILL QUERY&lt;/code&gt; terminates the statement the connection is currently executing, but leaves the connection itself intact. This can be useful if you have a specific query that is causing issues or is taking too long to execute, and you want to terminate only that query without affecting other queries or processes running on the same connection.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mysql&amp;gt; KILL QUERY 123&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  10. Quit - \q, quit, exit, Ctrl+D/Ctrl+Z
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mysql&amp;gt; &lt;span class="se"&gt;\q&lt;/span&gt;
Bye
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mysql&amp;gt; &lt;span class="nb"&gt;exit
&lt;/span&gt;Bye
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mysql&amp;gt; quit
Bye
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alternatively, you can use the shortcut key &lt;code&gt;Ctrl+D&lt;/code&gt; (or &lt;code&gt;Ctrl+Z&lt;/code&gt; on Windows).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mysql&amp;gt; ^DBye
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Other Tips
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Displaying query results vertically - \G
&lt;/h3&gt;

&lt;p&gt;Some query results are much more readable when displayed vertically using &lt;code&gt;\G&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mysql&amp;gt; SHOW GRANTS&lt;span class="se"&gt;\G&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;***************************&lt;/span&gt; 1. row &lt;span class="k"&gt;***************************&lt;/span&gt;
Grants &lt;span class="k"&gt;for &lt;/span&gt;root@%: GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON &lt;span class="k"&gt;*&lt;/span&gt;.&lt;span class="k"&gt;*&lt;/span&gt; TO &lt;span class="sb"&gt;`&lt;/span&gt;root&lt;span class="sb"&gt;`&lt;/span&gt;@&lt;span class="sb"&gt;`&lt;/span&gt;%&lt;span class="sb"&gt;`&lt;/span&gt; WITH GRANT OPTION
&lt;span class="k"&gt;***************************&lt;/span&gt; 2. row &lt;span class="k"&gt;***************************&lt;/span&gt;
Grants &lt;span class="k"&gt;for &lt;/span&gt;root@%: GRANT APPLICATION_PASSWORD_ADMIN,AUDIT_ABORT_EXEMPT,AUDIT_ADMIN,AUTHENTICATION_POLICY_ADMIN,BACKUP_ADMIN,BINLOG_ADMIN,BINLOG_ENCRYPTION_ADMIN,CLONE_ADMIN,CONNECTION_ADMIN,ENCRYPTION_KEY_ADMIN,FIREWALL_EXEMPT,FLUSH_OPTIMIZER_COSTS,FLUSH_STATUS,FLUSH_TABLES,FLUSH_USER_RESOURCES,GROUP_REPLICATION_ADMIN,GROUP_REPLICATION_STREAM,INNODB_REDO_LOG_ARCHIVE,INNODB_REDO_LOG_ENABLE,PASSWORDLESS_USER_ADMIN,PERSIST_RO_VARIABLES_ADMIN,REPLICATION_APPLIER,REPLICATION_SLAVE_ADMIN,RESOURCE_GROUP_ADMIN,RESOURCE_GROUP_USER,ROLE_ADMIN,SENSITIVE_VARIABLES_OBSERVER,SERVICE_CONNECTION_ADMIN,SESSION_VARIABLES_ADMIN,SET_USER_ID,SHOW_ROUTINE,SYSTEM_USER,SYSTEM_VARIABLES_ADMIN,TABLE_ENCRYPTION_ADMIN,XA_RECOVER_ADMIN ON &lt;span class="k"&gt;*&lt;/span&gt;.&lt;span class="k"&gt;*&lt;/span&gt; TO &lt;span class="sb"&gt;`&lt;/span&gt;root&lt;span class="sb"&gt;`&lt;/span&gt;@&lt;span class="sb"&gt;`&lt;/span&gt;%&lt;span class="sb"&gt;`&lt;/span&gt; WITH GRANT OPTION
&lt;span class="k"&gt;***************************&lt;/span&gt; 3. row &lt;span class="k"&gt;***************************&lt;/span&gt;
Grants &lt;span class="k"&gt;for &lt;/span&gt;root@%: GRANT PROXY ON &lt;span class="sb"&gt;``&lt;/span&gt;@&lt;span class="sb"&gt;``&lt;/span&gt; TO &lt;span class="sb"&gt;`&lt;/span&gt;root&lt;span class="sb"&gt;`&lt;/span&gt;@&lt;span class="sb"&gt;`&lt;/span&gt;%&lt;span class="sb"&gt;`&lt;/span&gt; WITH GRANT OPTION
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Further Readings
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.bytebase.com/blog/blog/how-to-install-mysql-client-on-mac-ubuntu-centos-windows"&gt;How to Install MySQL Client on Your Mac, Ubuntu, CentOS, Windows&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.bytebase.com/blog/blog/top-mysql-gui-client"&gt;Top MySQL GUI Clients&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.bytebase.com/blog/blog/top-mysql-schema-compare-tools"&gt;Top MySQL Schema Compare Tool to Diff and Sync Database&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.bytebase.com/blog/blog/top-open-source-sql-clients"&gt;Top Free, Open Source SQL Clients&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>productivity</category>
    </item>
    <item>
      <title>How to install MySQL Client on Your Mac, Ubuntu, CentOS, and Windows</title>
      <dc:creator>Tianzhou</dc:creator>
      <pubDate>Mon, 17 Jul 2023 07:10:24 +0000</pubDate>
      <link>https://dev.to/bytebase/how-to-install-mysql-client-on-your-mac-ubuntu-centos-and-windows-13b9</link>
      <guid>https://dev.to/bytebase/how-to-install-mysql-client-on-your-mac-ubuntu-centos-and-windows-13b9</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;The official &lt;a href="https://dev.mysql.com/doc/refman/8.0/en/mysql.html" rel="noopener noreferrer"&gt;MySQL Client&lt;/a&gt; &lt;code&gt;mysql&lt;/code&gt;, also known as MySQL CLI is a CLI to interact with your MySQL server. Below describe how to install it on Mac, Ubuntu, Debian and Windows respectively.&lt;/p&gt;

&lt;h2&gt;
  
  
  Before You Start
&lt;/h2&gt;

&lt;p&gt;Before you start, you should confirm that you don't have MySQL client installed. If you have installed MySQL server before, likely you will have MySQL client installed as well. If you see something like below, then MySQL client is already installed and you can stop reading now.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mysql --version
mysql  Ver 8.0.31 for macos13.0 on arm64 (Homebrew)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Test Connection
&lt;/h2&gt;

&lt;p&gt;After you install the MySQL client following the below instruction, you can test the connection to your MySQL server using&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mysql -h hostname -u username -p&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Install on Mac
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Homebrew
&lt;/h3&gt;

&lt;p&gt;To install MySQL Shell using &lt;a href="https://brew.sh/" rel="noopener noreferrer"&gt;Homebrew&lt;/a&gt;, you need to install Homebrew on your Mac first. If you aren’t sure if you have installed Homebrew already, open your terminal and run the following command to check.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;brew -v&lt;/code&gt;&lt;br&gt;
If not installed, run the following command to install Homebrew first:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once Homebrew is installed, run the following command to update the list of available packages:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;brew update&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To install the MySQL client, run the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;brew install mysql-client&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After the installation is complete, you can verify that the MySQL client is installed by running the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mysql --version&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Note: If you have previously installed the MySQL server using Homebrew, you may need to run the following command to link the MySQL client:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;brew link --overwrite mysql-client&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  DMG Package
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Go to the MySQL website and download the DMG package for the MySQL client. The current version can be found at &lt;a href="https://dev.mysql.com/downloads/mysql/" rel="noopener noreferrer"&gt;https://dev.mysql.com/downloads/mysql/&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Double-click the downloaded DMG file to mount it. A new window will appear with the MySQL package.&lt;/li&gt;
&lt;li&gt;Double-click the package to start the installation process, and follow the on-screen instructions to complete the installation.&lt;/li&gt;
&lt;li&gt;Once the installation is complete, you can verify that the MySQL client is installed by opening a Terminal window and running the following command:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;mysql --version&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This should display the version number of the MySQL client that you just installed.&lt;/p&gt;

&lt;p&gt;Note: If you have previously installed the MySQL server using a package manager like Homebrew, you may need to specify the path to the MySQL client binary when running commands. The default location for the MySQL client binary installed with the DMG package is /usr/local/mysql/bin/mysql.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ubuntu (apt-get)
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Open a terminal window on your Ubuntu machine. You can do this by pressing Ctrl+Alt+T on your keyboard.&lt;/li&gt;
&lt;li&gt;Update the package list and upgrade any installed packages by running the following commands:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get update
sudo apt-get upgrade
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install the MySQL client by running the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo apt-get install mysql-client&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After the installation is complete, you can verify that the MySQL client is installed by running the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mysql --version&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  CentOS (yum)
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Open a terminal window on your CentOS machine. You can do this by pressing Ctrl+Alt+T on your keyboard.&lt;/li&gt;
&lt;li&gt;Update the package list and upgrade any installed packages by running the following commands:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;sudo yum update&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install the MySQL client by running the following command:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;sudo yum install mysql&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;After the installation is complete, you can verify that the MySQL client is installed by running the following command:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;mysql --version&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Windows
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Go to the MySQL website and download the MySQL Installer for Windows at &lt;a href="https://dev.mysql.com/downloads/installer/" rel="noopener noreferrer"&gt;https://dev.mysql.com/downloads/installer/&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Run the MySQL Installer and select the "Custom" installation type.&lt;/li&gt;
&lt;li&gt;In the "Select Products and Features" screen, expand the "MySQL Servers" option and uncheck all the server components.&lt;/li&gt;
&lt;li&gt;In the same screen, expand the "Applications" option and check the "MySQL Shell" and "MySQL Workbench" options. These applications include the MySQL client.&lt;/li&gt;
&lt;li&gt;Complete the rest of the installation process.&lt;/li&gt;
&lt;li&gt;After the installation is complete, you can verify that the MySQL client is installed by opening a Command Prompt or PowerShell window and running the following command:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;mysql --version&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  More MySQL Tools
&lt;/h2&gt;

&lt;p&gt;The classic MySQL client is still the most widely used MySQL client. Meanwhile you can also check out following tools&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://www.bytebase.com/blog/how-to-install-mysql-shell-on-macos/" rel="noopener noreferrer"&gt;MySQL Shell&lt;/a&gt; &lt;code&gt;mysqlsh&lt;/code&gt; introduced in MySQL 8.0 to provide more advanced features over &lt;code&gt;mysql&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.bytebase.com/blog/top-mysql-gui-client/" rel="noopener noreferrer"&gt;Top MySQL GUI client&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.bytebase.com/blog/top-mysql-schema-compare-tools" rel="noopener noreferrer"&gt;Top MySQL Schema Compare Tool to Diff and Sync Database&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.bytebase.com/blog/top-open-source-sql-clients" rel="noopener noreferrer"&gt;Top Free Open Source SQL Clients&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
    <item>
      <title>What is a Database Schema?</title>
      <dc:creator>Tianzhou</dc:creator>
      <pubDate>Mon, 28 Nov 2022 03:59:31 +0000</pubDate>
      <link>https://dev.to/bytebase/what-is-a-database-schema-98</link>
      <guid>https://dev.to/bytebase/what-is-a-database-schema-98</guid>
      <description>&lt;p&gt;A database management system (DBMS) consists of three main components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The database server&lt;/li&gt;
&lt;li&gt;The database data&lt;/li&gt;
&lt;li&gt;The database schema&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The database server is a computation component and is stateless. The database data holds the state while the database schema holds the structure of the state (metadata). Database users often use SQL to instruct the database server to manipulate the underlying database data. SQL stands for &lt;em&gt;Structured Query Language&lt;/em&gt; which is based on the structure that the database schema provides.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Database Server
&lt;/h2&gt;

&lt;p&gt;The database server is a process or a set of processes running inside a computation environment. The computation environment provides processing power. It could be a physical computer, a &lt;a href="https://en.wikipedia.org/wiki/Virtual_machine" rel="noopener noreferrer"&gt;virtual machine&lt;/a&gt; or a lightweight &lt;a href="https://en.wikipedia.org/wiki/OS-level_virtualization" rel="noopener noreferrer"&gt;container&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Database Data
&lt;/h2&gt;

&lt;p&gt;The database data records the business application information such as order information, customer profile, etc. The database data is stored on the physical disk. People always use a cylinder to represent a database because, in old days, database data is stored there. Oracle, the world’s largest database company, headquarters are a set of cylinder buildings.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr0qie2yeyyyc3q0pt005.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr0qie2yeyyyc3q0pt005.png" alt="Image description" width="800" height="196"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Database Schema
&lt;/h2&gt;

&lt;p&gt;The database schema describes the &lt;strong&gt;logical structure&lt;/strong&gt; of the database data. It often resides together with the database data. A more general term is metadata, but in the database domain, it’s always referred to as database schema or just schema. Other synonyms include data dictionary, data catalog, etc.&lt;/p&gt;

&lt;p&gt;In the formal definition, a database schema is a set of formulas called integrity constraints. These constraints are defined as various database objects such as tables, fields, relationships, views, indexes, stored procedures, triggers, etc.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4jq1mh8umld1x9mj2e7o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4jq1mh8umld1x9mj2e7o.png" alt="Image description" width="800" height="672"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Above is a database schema for a database storing the employee data. The database schema is the &lt;strong&gt;most critical information&lt;/strong&gt; because it’s the blueprint of how the database data is organized. A DBMS can have a database schema with empty data, but not vice versa. The database data is meaningless without the database schema.&lt;/p&gt;

&lt;p&gt;Database schema evolves as the business evolves. In the next post, we will explain the evolution process, the database schema change.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
