MySQL

From LQWiki
(Redirected from MySql)
Jump to navigation Jump to search

MySQL is an open source RDBMS server that uses SQL for inserting, selecting and updating data. It's very fast, capable, flexible, and runs on UNIX, Linux, Mac and Windows platforms.

QuickStart

Install mysql from your distribution.

If Required by your distribution, install the initial database (e.g. Slackware requires this)

mysql_install-db --user=mysql

Start mysql on your local computer with

/etc/init.d/mysql start
#BSD style init (e.g. Slackware):
/etc/rc.d/rc.mysqld start

Build up a connection to mysql:

mysql --user root
mysql> show databases;

Set root's password.

mysql> set password = password("new_password");

Set up a GUI to administer your new mysql database.

Note: You may also want to use the following as it lets you set up the root password and removes the testing database.

mysql_secure_installation

Configure MySQL

To configure mysql you open a console and enter

mysql

Depending on your setup you may also have to give username and password like this:

mysql --user root --password password1

Show all databases

show databases;

Show all tables

To list all tables of the database database, issue

use database
show tables;

Show all users

select user from mysql.user;

Add a user

This adds a user named user1 with a password password1

mysql --user root --password password1
grant all on * to 'user1'@'localhost' identified by 'password1' with grant option;

Other Options

skip-networking will tell MySQL to not listen to the TCP/IP port. This is for databases that will only be accessed by the local machine. Why open a port if you don't have to?

un-comment in /etc/my.conf

skip-networking

OR add the option "--skip-networking" to the execution line in the startup script.

/usr/bin/mysqld_safe --skip-networking

MySQL GUIs

See also