MySQL Tutorials & TIPS

Importing database in command line
mysql -u root -ppassword Dbname < /home/user/path.sql
Exporting database DUMP in command line
mysql -u root -ppassword Dbname > /home/user/path.sql

Create database using command line

Mysql login in Linux command line

MySQL -u root -p

Then enter the password

Create database command

1.CREATE DATABASE example
CREATE DATABASE uan
2.SHOW DATABASES

3. use DATABASE

database changed it means it ready for import existing data.

import SQL file to the database

Change Varchar length of the column

ALTER TABLE 2wpjn_posts MODIFY COLUMN post_name VARCHAR(20);
Delete all WordPress posts by category PHPMyAdmin
delete a,b,c,d
FROM wp_posts a
LEFT JOIN wp_term_relationships b ON ( a.ID = b.object_id )
LEFT JOIN wp_postmeta c ON ( a.ID = c.post_id )
LEFT JOIN wp_term_taxonomy d ON ( d.term_taxonomy_id = b.term_taxonomy_id )
LEFT JOIN wp_terms e ON ( e.term_id = d.term_id )
WHERE e.term_id = 1
term_id= category ID you will see it while editing category on URL.

MySQL login exit Linux command line

CTRL+D
Example Replacing string /Int char in SQL table

UPDATE smf_messages SET body = replace(body, ”

[html]", "[/html]

“);

<iframe src =”http://www.apspdcl.in/ExamResult/se_search_form.htm” width=”100%” height=”400″> </iframe>
<a href=”theonlineking.com”onclick=”window.open
(”http://www.theonlineking.com”,”popup”,’width=1027,height=760,left=100,top=0′); return false”><b><big><i><u>Click here for results and other..</b></big></i></u></a>

<iframe src =” <a href=”theonlineking.com”onclick=”window.open
(‘
UPDATE smf_messages SET body = replace(body, “<iframe src =””, “<a href=”theonlineking.com”onclick=”window.open (‘”);

” width=”100%” height=”400″> </iframe>  ‘,’popup’,’width=1027,height=760,left=100,top=0′); return false”><b><big><i><u>Click here for results and other..</b></big></i></u></a>

UPDATE smf_messages SET body = replace(body, ”

[html]", "[/html]

“);

Replace

copy table
duplicate table

References
https://www.liquidweb.com/kb/create-a-mysql-database-on-linux-via-command-line/