{"id":18427,"date":"2026-09-30T07:34:00","date_gmt":"2026-09-30T04:34:00","guid":{"rendered":"https:\/\/www.hyyat.com\/knowledgebase\/mysql-commands-ssh\/"},"modified":"2026-11-22T18:53:07","modified_gmt":"2026-11-22T15:53:07","password":"","slug":"mysql-commands-ssh","status":"publish","type":"docs","link":"https:\/\/www.hyyat.com\/en\/knowledgebase\/mysql-commands-ssh\/","title":{"rendered":"Working with MySQL and MariaDB from the Command Line: Logging In, Querying, and Creating a Database and User"},"content":{"rendered":"<div class=\"hkb\" dir=\"ltr\">\n<div class=\"hkb-tldr\"><b>The first five commands<\/b>Log in with <code>mysql<\/code> (on a cPanel server root reads its details from <code>\/root\/.my.cnf<\/code>), then <code>SHOW DATABASES;<\/code>, <code>USE db_name;<\/code> and <code>SHOW TABLES;<\/code>. To create a database and user: <code>CREATE DATABASE<\/code>, <code>CREATE USER<\/code>, then <code>GRANT<\/code>. On a cPanel server, create them in cPanel so they appear in its interface.<\/div>\n<div class=\"hy-vid\"><div style=\"width: 1280px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-18427-1\" width=\"1280\" height=\"720\" poster=\"https:\/\/www.hyyat.com\/zasogooh\/2026\/11\/hyyat-srv-sqlshell-en.jpg\" preload=\"none\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/www.hyyat.com\/zasogooh\/2026\/11\/hyyat-srv-sqlshell-en.mp4?_=1\" \/><a href=\"https:\/\/www.hyyat.com\/zasogooh\/2026\/11\/hyyat-srv-sqlshell-en.mp4\">https:\/\/www.hyyat.com\/zasogooh\/2026\/11\/hyyat-srv-sqlshell-en.mp4<\/a><\/video><\/div><\/div>\n<div class=\"hkb-note\"><b>The idea:<\/b> phpMyAdmin is comfortable, but the command line is faster for big jobs and works even when the interfaces are down. Every MySQL statement ends with a semicolon.<\/div>\n<h2>Logging in<\/h2>\n<div class=\"hkb-tbl\">\n<table>\n<thead>\n<tr>\n<th>Case<\/th>\n<th>Command<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>root on a cPanel server<\/td>\n<td><code>mysql<\/code> directly<\/td>\n<\/tr>\n<tr>\n<td>A specific database user<\/td>\n<td><code>mysql -u user_db -p user_dbname<\/code>, then the password<\/td>\n<\/tr>\n<tr>\n<td>A server without a panel<\/td>\n<td><code>mysql -u root -p<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2>Commands you use every day<\/h2>\n<figure class=\"hkb-fig\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.hyyat.com\/zasogooh\/2026\/11\/hkb-sv-t-sql.webp\" alt=\"Basic MySQL commands for listing databases and tables, querying and creating a database\" width=\"800\" height=\"451\" loading=\"lazy\" \/><\/figure>\n<div class=\"hkb-tbl\">\n<table>\n<thead>\n<tr>\n<th>Command<\/th>\n<th>What it does<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>SHOW DATABASES;<\/code><\/td>\n<td>Every database<\/td>\n<\/tr>\n<tr>\n<td><code>USE example_wp;<\/code><\/td>\n<td>Pick a database<\/td>\n<\/tr>\n<tr>\n<td><code>SHOW TABLES;<\/code><\/td>\n<td>Tables in the chosen database<\/td>\n<\/tr>\n<tr>\n<td><code>DESCRIBE wp_users;<\/code><\/td>\n<td>A table\u2019s columns<\/td>\n<\/tr>\n<tr>\n<td><code>SELECT COUNT(*) FROM wp_posts;<\/code><\/td>\n<td>Row count<\/td>\n<\/tr>\n<tr>\n<td><code>SHOW PROCESSLIST;<\/code><\/td>\n<td>Queries running now<\/td>\n<\/tr>\n<tr>\n<td><code>EXIT;<\/code><\/td>\n<td>Leave<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2>Worked example: WordPress URL after a move<\/h2>\n<pre class=\"hkb-code\">USE example_wp;\nSELECT option_name, option_value FROM wp_options\n  WHERE option_name IN (&#x27;siteurl&#x27;,&#x27;home&#x27;);\nUPDATE wp_options SET option_value=&#x27;https:\/\/example.com&#x27;\n  WHERE option_name IN (&#x27;siteurl&#x27;,&#x27;home&#x27;);<\/pre>\n<p>Watch the table prefix: it is not always wp_. Find it in wp-config.php.<\/p>\n<h2>Creating a database and user<\/h2>\n<pre class=\"hkb-code\">CREATE DATABASE app_db;\nCREATE USER &#x27;app_user&#x27;@&#x27;localhost&#x27; IDENTIFIED BY &#x27;StrongPass#2026&#x27;;\nGRANT ALL PRIVILEGES ON app_db.* TO &#x27;app_user&#x27;@&#x27;localhost&#x27;;\nFLUSH PRIVILEGES;<\/pre>\n<div class=\"hkb-note warn\">On a cPanel server, create databases for accounts in cPanel or with WHM tools. A database created on the command line without linking it to an account will not show in cPanel or be included in its backups. If you do create one by hand, link it with <b>Database Map Tool<\/b> in WHM.<\/div>\n<h2>Common errors<\/h2>\n<div class=\"hkb-tbl\">\n<table>\n<thead>\n<tr>\n<th>Message<\/th>\n<th>Cause<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>Access denied for user<\/code><\/td>\n<td>Wrong password, or the user has no rights on this database<\/td>\n<\/tr>\n<tr>\n<td><code>Unknown database<\/code><\/td>\n<td>Wrong name; remember the prefix, such as user_dbname<\/td>\n<\/tr>\n<tr>\n<td><code>ERROR 1064<\/code><\/td>\n<td>A syntax error, usually a comma or quote<\/td>\n<\/tr>\n<tr>\n<td><code>Can\u2019t connect to local server through socket<\/code><\/td>\n<td>The database service is stopped. Restart it as in <a href=\"https:\/\/www.hyyat.com\/en\/knowledgebase\/restart-services-whm\/\">restarting services<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>To import a large file or export a copy, see <a href=\"https:\/\/www.hyyat.com\/en\/knowledgebase\/import-mysql-database-ssh\/\">importing and exporting over SSH<\/a>.<\/p>\n<h2>A quick copy before any change<\/h2>\n<p>Before any UPDATE or DELETE on real data, copy the table inside the database in a second:<\/p>\n<pre class=\"hkb-code\">CREATE TABLE wp_options_backup AS SELECT * FROM wp_options;\n-- once the change is confirmed:\nDROP TABLE wp_options_backup;<\/pre>\n<p>If something goes wrong, restore with <code>INSERT<\/code> from the backup table. This small habit saves many sites from a hasty command missing its WHERE clause.<\/p>\n<h2>MySQL questions<\/h2>\n<div class=\"hkb-faq\">\n<details>\n<summary>Where is the database root password on cPanel?<\/summary>\n<p>In \/root\/.my.cnf, which is why mysql works directly for root. Do not share it.<\/p>\n<\/details>\n<details>\n<summary>Can UPDATE and DELETE be undone?<\/summary>\n<p>No. Copy the table or database before any bulk change.<\/p>\n<\/details>\n<details>\n<summary>Are the commands the same in MariaDB?<\/summary>\n<p>Yes, the basics are identical.<\/p>\n<\/details>\n<details>\n<summary>How do I see each database\u2019s size?<\/summary>\n<p>With a query on information_schema that sums table sizes per database, or from WHM\u2019s database tools.<\/p>\n<\/details>\n<\/div>\n<div class=\"hkb-rel\"><b>Related guides<\/b><\/p>\n<ul>\n<li><a href=\"https:\/\/www.hyyat.com\/en\/knowledgebase\/import-mysql-database-ssh\/\">How to Import a Large MySQL Database over SSH<\/a><\/li>\n<li><a href=\"https:\/\/www.hyyat.com\/en\/knowledgebase\/enable-remote-mysql\/\">Connecting to a MySQL Database from Outside the Server: WHM, cPanel Remote Database Access and the Firewall<\/a><\/li>\n<li><a href=\"https:\/\/www.hyyat.com\/en\/knowledgebase\/upgrading-mysql-to-mariadb-on-a-cpanel-whm-server\/\">Upgrading MySQL or MariaDB on a cPanel Server with Upgrade Database Version: The Five Steps and What Cannot Be Undone<\/a><\/li>\n<li><a href=\"https:\/\/www.hyyat.com\/en\/knowledgebase\/how-to-connect-to-a-server-via-ssh\/\">Connecting to Your Server Remotely with SSH: From Windows, macOS and Linux, and SSH Keys Instead of Passwords<\/a><\/li>\n<\/ul>\n<p><a href=\"https:\/\/www.hyyat.com\/en\/kb\/servers-without-control-panel\/\">All server guides \u2192<\/a><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>The first five commandsLog in with mysql (on a cPanel server root reads its details from \/root\/.my.cnf), then SHOW DATABASES;, USE db_name; and SHOW TABLES;. To create a database and user: CREATE DATABASE, CREATE USER, then GRANT. On a cPanel server, create them in cPanel so they appear in its interface. The idea: phpMyAdmin is [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":21309,"comment_status":"open","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"_templately_pack_id":"","_templately_imported_at":"","_templately_source":"","_templately_import_session_id":"","footnotes":""},"doc_category":[2733],"doc_tag":[],"class_list":["post-18427","docs","type-docs","status-publish","has-post-thumbnail","hentry","doc_category-servers-without-control-panel"],"year_month":"2026-11","word_count":596,"total_views":0,"reactions":{"happy":0,"normal":0,"sad":0},"author_info":{"name":"ahmed fathy","author_nicename":"ahmed-fathy","author_url":"https:\/\/www.hyyat.com\/en\/author\/ahmed-fathy\/"},"doc_category_info":[{"term_name":"Servers Without a Control Panel","term_url":"https:\/\/www.hyyat.com\/en\/kb\/servers-without-control-panel\/"}],"doc_tag_info":[],"knowledge_base_info":[],"knowledge_base_slug":[],"_links":{"self":[{"href":"https:\/\/www.hyyat.com\/en\/wp-json\/wp\/v2\/docs\/18427","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hyyat.com\/en\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/www.hyyat.com\/en\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/www.hyyat.com\/en\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hyyat.com\/en\/wp-json\/wp\/v2\/comments?post=18427"}],"version-history":[{"count":0,"href":"https:\/\/www.hyyat.com\/en\/wp-json\/wp\/v2\/docs\/18427\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hyyat.com\/en\/wp-json\/wp\/v2\/media\/21309"}],"wp:attachment":[{"href":"https:\/\/www.hyyat.com\/en\/wp-json\/wp\/v2\/media?parent=18427"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/www.hyyat.com\/en\/wp-json\/wp\/v2\/doc_category?post=18427"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/www.hyyat.com\/en\/wp-json\/wp\/v2\/doc_tag?post=18427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}