Difference between revisions of "MySQL Commands"
Jump to navigation
Jump to search
(Created page with "== Miscellanious MySQL Query Commands == * Login into a MySQL database server from the Linux command line with a user name and have it prompt for the password: <pre style="color:...") |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
== Miscellanious MySQL Query Commands == | == Miscellanious MySQL Query Commands == | ||
− | * Login into a MySQL database server from the Linux command line with | + | * Login into a MySQL database server from the Linux command line with your user name and have it prompt for the password: |
<pre style="color:blue">$ mysql -p</pre><br> | <pre style="color:blue">$ mysql -p</pre><br> | ||
− | * Display all available datases: | + | * Display all available datases(from the mysql> command prompt): |
<pre style="color:blue">mysql> show databases;</pre><br> | <pre style="color:blue">mysql> show databases;</pre><br> | ||
* Select a database(where database_name is the name of the database you want to use): | * Select a database(where database_name is the name of the database you want to use): | ||
Line 10: | Line 10: | ||
* Dislpay all data in a specific table(where table_name is the name of the table you want to use): | * Dislpay all data in a specific table(where table_name is the name of the table you want to use): | ||
<pre style="color:blue">mysql> select * from table_name;</pre><br> | <pre style="color:blue">mysql> select * from table_name;</pre><br> | ||
− | * Display the number of rows in a | + | * Display the number of rows in a specific table(where table_name is the name of the table you want to count the rows): |
− | <pre style="color:blue">mysql select count(*) from table_name;</pre><br> | + | <pre style="color:blue">mysql> select count(*) from table_name;</pre><br> |
− | <br><br> | + | * Display column names of a table(where table_name is the name of the table you want to use): |
+ | <pre style="color:blue">mysql> describe table_name;</pre><br> | ||
+ | * Select rows searching by column name(location) if it's not NULL(not empty and has a value) and display other column data(display realname & location): | ||
+ | (This example uses one of my actual databases for the table name and column names) | ||
+ | <pre style="color:blue">mysql> select realname,location from dawg_users where location is not null;</pre><br> | ||
+ | <br> |
Latest revision as of 15:53, 9 June 2013
Miscellanious MySQL Query Commands
- Login into a MySQL database server from the Linux command line with your user name and have it prompt for the password:
$ mysql -p
- Display all available datases(from the mysql> command prompt):
mysql> show databases;
- Select a database(where database_name is the name of the database you want to use):
mysql> use database_name;
- Display all tables in a database which has been selected:
mysql> show tables;
- Dislpay all data in a specific table(where table_name is the name of the table you want to use):
mysql> select * from table_name;
- Display the number of rows in a specific table(where table_name is the name of the table you want to count the rows):
mysql> select count(*) from table_name;
- Display column names of a table(where table_name is the name of the table you want to use):
mysql> describe table_name;
- Select rows searching by column name(location) if it's not NULL(not empty and has a value) and display other column data(display realname & location):
(This example uses one of my actual databases for the table name and column names)
mysql> select realname,location from dawg_users where location is not null;