Mysql Commands For DB
Mysql Commands For DB
Mysql Commands For DB
If you have fresh installation of MySQL server, then it doesnt required any password to connect it as root user. To set MySQL password for root user,
use the following command.
Enter password:
mysqld is alive
Enter password:
mysqladmin Ver 8.42 Distrib 5.5.28, for Linux on i686
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All
rights reserved.
Oracle is a registered trademark of Oracle Corporation
and/or its
affiliates. Other names may be trademarks of their
respective
owners.
Server version
Protocol version
Connection
UNIX socket
Uptime:
5.5.28
10
Localhost via UNIX socket
/var/lib/mysql/mysql.sock
7 days 14 min 45 sec
To find out current status of MySQL server, use the following command. The mysqladmincommand shows the status of uptime with
running threads and queries.
Enter password:
Uptime: 606704 Threads: 2 Questions: 36003 Slow queries:
0 Opens: 15 Flush tables: 1 Open tables: 8 Queries per
second avg: 0.059
6. How to check status of all MySQL Server Variables and values?
To check all the running status of MySQL server variables and values, type the following command. The output would be similar to below.
Enter password:
+------------------------------------------+-------------+
| Variable_name
| Value
+------------------------------------------+-------------+
| Aborted_clients
| 3
| Aborted_connects
| 3
| Binlog_cache_disk_use
| 0
| Binlog_cache_use
| 0
| Binlog_stmt_cache_disk_use
| 0
| Binlog_stmt_cache_use
| 0
| Bytes_received
| 6400357
| Bytes_sent
| 2610105
| Com_admin_commands
| 3
| Com_assign_to_keycache
| 0
| Com_alter_db
| 0
| Com_alter_db_upgrade
| 0
| Com_alter_event
| 0
| Com_alter_function
| 0
| Com_alter_procedure
| 0
| Com_alter_server
| 0
| Com_alter_table
| 0
| Com_alter_tablespace
| 0
+------------------------------------------+-------------+
7. How to see all MySQL server Variables and Values?
To see all the running variables and values of MySQL server, use the command as follows.
# mysqladmin
-u root -p variables
Enter password:
+---------------------------------------------------+---------------------------------------------+
| Variable_name
|
| Value
+---------------------------------------------------+---------------------------------------------+
| auto_increment_increment
|
| 1
| auto_increment_offset
|
| 1
| autocommit
|
| ON
| automatic_sp_privileges
|
| ON
| back_log
|
| 50
| basedir
|
| /usr
| big_tables
|
| OFF
| binlog_cache_size
|
| 32768
| binlog_direct_non_transactional_updates
|
| OFF
| binlog_format
STATEMENT
|
|
| binlog_stmt_cache_size
|
| 32768
| bulk_insert_buffer_size
8388608
|
|
| character_set_client
latin1
| character_set_connection
latin1
| character_set_database
latin1
| character_set_filesystem
binary
| character_set_results
latin1
| character_set_server
latin1
|
|
|
|
|
|
|
|
|
| character_set_system
|
| utf8
| character_sets_dir
/usr/share/mysql/charsets/
| collation_connection
latin1_swedish_ci
|
|
|
+---------------------------------------------------+---------------------------------------------+
Enter password:
+-------+---------+-----------------+---------+---------+-----+-------+------------------+
| Id
| User
| Host
Time | State | Info
| db
| Command |
+-------+---------+-----------------+---------+---------+-----+-------+------------------+
| 18001 | rsyslog | localhost:38307 | rsyslog | Sleep
5590 |
|
|
| 18020 | root
| localhost
|
| show processlist |
| 0
| Query
+-------+---------+-----------------+---------+---------+-----+-------+------------------+
9. How to create a Database in MySQL server?
To create a new database in MySQL server, use the command as shown below.
Enter password:
# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.
+--------------------+
| information_schema |
| databasename
|
| mysql
|
| test
|
+--------------------+
8 rows in set (0.01 sec)
mysql>
10. How to drop a Database in MySQL server?
To drop a Database in MySQL server, use the following command. You will be asked to confirm press y.
Enter password:
Dropping the database is potentially a very bad thing to
do.
Enter password:
You can also use the following commands to start/stop MySQL server.
# /etc/init.d/mysqld stop
# /etc/init.d/mysqld start
13. Some useful MySQL Flush commands
Following are some useful flush commands with their description.
flush-hosts: Flush all host information from host cache.
flush-tables: Flush all tables.
flush-threads: Flush all threads cache.
flush-logs: Flush all information logs.
flush-privileges: Reload the grant tables (same as reload).
flush-status: Clear status variables.
o
o
o
o
o
o
Enter password:
+----+------+-----------+----+---------+------+-------+-----------------+
| Id | User | Host
Info
|
+----+------+-----------+----+---------+------+-------+-----------------+
| 5
| root | localhost |
| Sleep
| 14
| 8 | root | localhost |
show processlist |
| Query
| 0
+----+------+-----------+----+---------+------+-------+-----------------+
Now, run the following command with kill and process ID as shown below.
Enter password:
+----+------+-----------+----+---------+------+-------+-----------------+
| Id | User | Host
Info
|
+----+------+-----------+----+---------+------+-------+-----------------+
| 12 | root | localhost |
show processlist |
| Query
| 0
+----+------+-----------+----+---------+------+-------+-----------------+
If you like to kill multiple process, then pass the process IDs with comma separated as shown below.
# mysqladmin
Enter password:
+----+------+-----------+----+---------+------+-------+-----------------+
| Id | User | Host
Info
|
+----+------+-----------+----+---------+------+-------+-----------------+
| 8 | root | localhost |
show processlist |
| Query
| 0
+----+------+-----------+----+---------+------+-------+-----------------+
Uptime: 3801 Threads: 1 Questions: 15 Slow queries: 0
Opens: 15 Flush tables: 1 Open tables: 8 Queries per
second avg: 0.003
mysqladmin
Server version
5.5.28
Protocol version
10
Connection
UNIX socket
/var/lib/mysql/mysql.sock
Uptime:
# mysqladmin
-h 172.16.25.126 -u root -p
# mysqladmin
# mysqladmin
-u root -p start-slave
# mysqladmin
-u root -p stop-slave
# mysqladmin
-u root -p debug
Enter password:
20. How to view mysqladmin options and usage
To find out more options and usage of myslqadmin command use the help command as shown below. It will display a list of available options.
# mysqladmin --help
We have tried our best to include almost all of mysqladmin commands with their examples in this article, If still, weve missed anything, please do let us know via
comments and dont forget to share with your friends.