MySQL

From SME Server
Revision as of 00:39, 25 March 2007 by Cactus (talk | contribs) (Placed the login instruction for MySQL)
Jump to navigation Jump to search

MySQL Database

SME Server runs MySQL as a database server. There are a lot of applications require a MySQL database, among them is the Horde webmail interface which is supplied by SME Server by default.

Usefull links

General

The SME Server is based on CentOS, the development team will take their stock RPM's from the CentOS releases. The current version of MySQL installed on SME Server is version 4.1.20.

You can upgrade MySQL to a higher version but you are advised not to do so, as this might break your SME Server configuration. The Horde webmail interface relies on MySQL. Upgrading to version 5.x is known to break stuff like webmail. If you insist on upgrading MySQL you may be able to find instructions in the forum, but be advised that no support can be expected from the developers and all bugs reported in the bugtracker will not be taken into account.

MySQL on SME Server runs on a socket instead of on a port which you might be accustomed to. This is done to improve security as in the view of the development team only the server self needs to have access to the MySQL server. However you can configure MySQL to be accessible from the local network

MySQL root password

There seems to be no password set for the MySQL root password, but this is not true. If you are logged in to the SME Server shell a special mechanism is in place to log you in with MySQL root privileges without prompting you for the password.

The MySQL root password for SME Server is a 72 character random string generated during installation of SME Server. You should never change the MySQL root password as this will break your SME Server configuration. How to login as MySQL root user? describes how to access MySQL with root privileges on SME Server.

Login as MySQL root user

To login as MySQL root user, simply type 'mysql' at the SME Server shell, this will log you in with root privileges.

Resetting the MySQL root password

To reset the password for the MySQL root account. The MySQL root user on SME Server has a random generated password which is generated during installation. You do not need to know this password to login to MySQL with root privileges on SME Server. If you might have changed the MySQL root password you can reset it like this after getting command line access as root user:

 cd /var/service/mysqld
 runsvctrl d .
 expand-template /root/.my.cnf
 expand-template /var/service/mysqld/set.password
 /usr/libexec/mysqld --bootstrap --user=mysql --skip-grant-tables < ./set.password
 runsvctrl u .

Access MySQL from the local network

To access MySQL from my local network Because MySQL on SME Sverer is ran on a socket instead of a on a port MySQL on SME Server is by default configured to allow only local connections to improve security, this means that it is only accessible from the server it self and not from the local network nor from the internet. If you wish to enable local network access, execute the following commands on a SME Server shell as root:

 config setprop mysqld LocalNetworkingOnly no
 expand-template /etc/my.cnf
 /etc/rc.d/init.d/mysqld restart

Administration

To create a new database

  • See the developers guide if you wish to automate the creation of a database within an rpm

or

  • Get command line access and issue the following commands:
 mysqladmin createdatabase 'name'

This will create an empty database called name.

Template:DrawBoxWarning

To create a new MySQL user. Decide which permissions you will have to give to the user on what database. Details about this can be found in the MySQL Manual found at the MySQL site. Get access to the SME Server shell and issue the following commands to login to the MySQL server:

 mysql

Suppose we want to create a user which has read-only access on all tables in the database called 'test':

GRANT SELECT ON test.* TO 'user'@'host' IDENTIFIED BY 'password';

In the above line you will have to fill in the user and the host and/or domain from which you will allow the user access to the SME Server MySQL server (don't forget the single quotes). More information can be found in the MySQL Server Manual at the MySQL website linked here.