Mysql: Difference between revisions

From roonics
Jump to navigation Jump to search
No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 4: Line 4:
<pre>mysql -u <username> -p</pre>
<pre>mysql -u <username> -p</pre>


===test===
===Show process list===
<pre>mysqladmin -p processlist</pre>
 
or if already connected to MySQL
 
<pre>show processlist;</pre>
 
===Kill query===
<pre>KILL QUERY <id>;</pre>
 
===Create database===
<pre>CREATE DATABASE <db_name;</pre>
 
===Show databases===
<pre>show databases;</pre>
 
===Select database===
<pre>use <db_name>;</pre>
 
===Show tables===
<pre>show tables;</pre>
 
===Show table layout===
<pre>describe <table_name>;</pre>
 
===Create a MySQL user===
<pre>CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';</pre>
Replace username and password with the username and password required
 
===Grant permissions to a database===
<pre>GRANT ALL PRIVILEGES ON database.* to username@localhost;</pre>
Replace database and username with the database and username required
 
Once this has been run, run the below command to flush privileges:
<pre>FLUSH PRIVILEGES;</pre>
 
Finally this command to verify:
<pre>SHOW GRANTS FOR 'username'@'localhost';</pre>
 
===Set MySQL root password===
<pre>/usr/bin/mysqladmin -u root password 'password'</pre>
Replace the 2nd password with what you want the password to be.
 
[[Category:mysql]]
[[Category:linux]]
 
‎<comments />

Latest revision as of 15:05, 14 April 2022

MySQL

Useful Commands

Connect to database

mysql -u <username> -p

Show process list

mysqladmin -p processlist

or if already connected to MySQL

show processlist;

Kill query

KILL QUERY <id>;

Create database

CREATE DATABASE <db_name;

Show databases

show databases;

Select database

use <db_name>;

Show tables

show tables;

Show table layout

describe <table_name>;

Create a MySQL user

CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';

Replace username and password with the username and password required

Grant permissions to a database

GRANT ALL PRIVILEGES ON database.* to username@localhost;

Replace database and username with the database and username required

Once this has been run, run the below command to flush privileges:

FLUSH PRIVILEGES;

Finally this command to verify:

SHOW GRANTS FOR 'username'@'localhost';

Set MySQL root password

/usr/bin/mysqladmin -u root password 'password'

Replace the 2nd password with what you want the password to be.

‎<comments />