Difference between pages "Main Page" and "MySQL"

From Wikislax
(Difference between pages)
Jump to: navigation, search
 
(Created page with "{{RightTOC}} == What is MySQL ? == [http://www.mysql.com MySQL] is the traditional Database software companion to Apache and PHP. MySQL was previously a property of MySQL AB...")
 
Line 1: Line 1:
 
{{RightTOC}}
 
{{RightTOC}}
  
== Linux server ==
+
== What is MySQL ? ==
  
This guide is intended as a set of '''recipes''' installing and configuring '''essential Linux server software'''. The goal is to save your time ... and mine :) (re)installing a truly functional '''home''' server, learning on the way. '''Home''' server means the set of services or software listed below. Professional features such as backups, raid, lvm, clusters, automation, etc... are not covered here.
+
[http://www.mysql.com MySQL] is the traditional Database software companion to Apache and PHP. MySQL was previously a property of MySQL AB but was acquired by Oracle Corporation in 2010. This created some worries in the OpenSource community, which led to create a fork, [https://mariadb.org/ MariaDB], which is a plug-in replacement for MySQL and the one included in the Slackware distribution.
  
The recipes are based on '''slackware''' (64 bits - currently installing '''14.2'''). My reasons for preferring Slackware are simplicity and stability of this distribution. Also, Slackware does not hide what you need to know, and goes straight to the point. Last, Slackware gives good control on package installation. Sometimes we will however prefer to install server software not from packages, but from source.
+
== Installing MySQL ==
  
'''Installing software from source''' is not more difficult than using a graphical package manager that will hide most of what you '''''need''''' to know – specially regarding compilation options and – to some extent, location and content of configuration files. This guide will instead strive to show you what really happens under the hood. The knowledge in this guide should be reusable on any other Linux distribution appropriate for your needs.
+
The quickest way to install MySQL is to NOT install it and use instead [https://mariadb.org/ MariaDB], included with Slackware. If this is your choice, please note that '''/usr''' will be the root directory of the software instead of '''/usr/local/mysql''', and proceed to [[MySQL#Running SQL|Running SQL]].
  
<br/>
+
'''apr''' and '''apr-util''', used by apache, refer to MySQL so the latter must be installed first. [http://dev.mysql.com/downloads/mysql/ Download] the latest stable version, choosing "Source Code" when asked to Select platform. [http://dev.mysql.com/doc/ Documentation] is available from the web site. Here MySQL is compiled with OpenSSL support to be able to encrypt MySQL connections on port 3306 (just in case, as we don't intend to open port 3306 to the external world at the moment).
 +
 
 +
# groupadd mysql
 +
# useradd -g mysql mysql
 +
# tar -C /usr/local -xvf mysql-x.y.z.tar.gz
 +
# cd /usr/local/mysql-x.y.z
 +
# chown -R root:root .
 +
# less INSTALL-SOURCE
 +
# rm CMakeCache.txt
 +
# make clean
 +
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DINSTALL_LIBDIR=lib64 \
 +
-DINSTALL_PLUGINDIR=lib64/plugin -DMYSQL_DATADIR=/var/lib/mysql \
 +
-DDEFAULT_CHARSET=latin1 -DDEFAULT_COLLATION=latin1_swedish_ci \
 +
-DMYSQL_UNIX_ADDR=/var/run/mysql/mysql.sock -DWITH_SSL=yes
 +
# make
 +
# removepkg /var/log/packages/mysql-5.1.46-x86_64-2
 +
# make install
 +
# make clean
 +
# cp -R /usr/local/mysql/man /usr/local
 +
# cp support-files/my-default.cnf /etc/my.cnf
 +
# chmod u+x scripts/mysql_install_db
 +
# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/var/lib/mysql
 +
 
 +
== Configuring MySQL ==
 +
 
 +
MySQL ('''5.6.24''') works correctly out of the box so there is nothing to do really. In the past we had to edit '''/etc/my.cnf''' to uncomment line '''#skip-networking''' to prevent MySQL network connections. We also had to include in this file, after the '''[client]''' tag a line '''default-character-set=''charset_name''''' (for instance '''utf8''' or '''latin1''') to eliminate this warning when launching a client :
 +
 
 +
# mysql -u root -p
 +
Enter password:
 +
'''mysql: Unknown OS character set 'ISO-8859-15'.'''
 +
'''mysql: Switching to the default character set 'latin1'.'''
 +
Welcome to the MySQL monitor.  Commands end with ; or \g.
 +
. . .
  
== Installing Linux ==
+
This is no longer necessary, so let us directly update '''/etc/rc.d/rc.mysqld''' with new paths and options :
  
{| {{thead}}
+
# Start mysqld:
|-
+
mysqld_start() {
! {{chead}} width="150" | Topic
+
  if [ -x /usr'''/local/mysql'''/bin/mysqld_safe ]; then
! {{chead}} | Goal
+
    # If there is an old PID file (no mysqld running), clean it up:
|-
+
    if [ -r /var/run/mysql/mysql.pid ]; then
| [[Choosing a System]]
+
      if ! ps axc | grep mysqld 1> /dev/null 2> /dev/null ; then
| reasons for choosing Linux and Slackware for server usage
+
        echo "Cleaning up old /var/run/mysql/mysql.pid."
|-
+
        rm -f /var/run/mysql/mysql.pid
| [[Managing partitions]]
+
      fi
| manage systems coexistence and get systems to boot
+
    fi
|-
+
    /usr'''/local/mysql'''/bin/mysqld_safe '''--character_set_server=utf8''' \
| [[DVDless install]]
+
        '''--basedir=/usr/local/mysql''' --datadir=/var/lib/mysql \
| Slackware setup to install from Network
+
        --pid-file=/var/run/mysql/mysql.pid $SKIP &
|-
+
  fi
| [[Installing Slackware]]
+
}
| brief overview of the installation process
 
|-
 
| [[Maintaining Slackware]]
 
| how to keep Slackware current security-wise
 
|-
 
| [[Linux basics]]
 
| key information using a Linux system
 
|-
 
| [[Configuration files]]
 
| key slackware configuration files locations
 
|-
 
| [[IPTables]]
 
| firewall - filtering Internet communications
 
|-
 
| [[X11 configuration]]
 
| configuration of the X11 graphical system
 
|-
 
| [[X11 over the network]]
 
| using the X11 graphical system over the network
 
|-
 
| [[Compiling the Kernel]]
 
| customizing and optimizing your kernel
 
|-
 
| [[Compiling from Source]]
 
| installing sofware from source
 
|}
 
  
<br clear=all>
+
== Running SQL ==
  
== Xen virtualization ==
+
Give execution rights to the rc.mysqld script and launch the daemon :
  
{| {{thead}}
+
# chmod u+x /etc/rc.d/rc.mysqld
|-
+
# /etc/rc.d/rc.mysqld start
! {{chead}} width="150" | Topic
 
! {{chead}} | Goal
 
|-
 
| [[Compiling Xen]]
 
| what is Xen and how to compile
 
|-
 
| [[Using Grub2]]
 
| using Grub2 as the bootloader
 
|-
 
| [[Creating VMs]]
 
| creating and using virtual machines
 
|}
 
  
<br clear=all>
+
== Using MySQL ==
  
== Internet software ==
+
For a quick introduction on MySQL refer to this [http://www3.ntu.edu.sg/home/ehchua/programming/sql/MySQL_Intermediate.html overview]. Otherwise, if you have time to invest, MySQL comes with a very exhaustive [http://dev.mysql.com/doc documentation], including a tutorial. A few quick notes however :
  
Most of the server software can be installed directly from the distribution release to save time and effort. However, Server software must include only these compile options required and be updated quickly in case of security advisory, so we will compile it from source. The installation order below must be respected :
+
Mysql defines a root user without an initial password. '''mysqladmin''' makes is possible to specify one by typing '''/usr(/local/mysql)/bin/mysqladmin -u root -p password ‘new-password’'''. The old password is then requested. Type return (the old password is empty). From that point, the password will need to be specified for every  client invocation, for example : '''"/usr(/local/mysql)/bin/mysql -u root -p mysql_db"'''. '''"-p"''' with no value means that the password will be requested interactively. '''mysql_db''' is the database name. Not specifying the password on the command line affords avoiding potential disclosure to other users using '''ps'''.
  
{| {{thead}}
+
You can use '''mysql''' to configure itself. Refer to the [http://dev.mysqm.com/doc/ documentation] for the '''SQL''' syntax, or use [[phpMyAdmin]], a PHP application to manage MySql from your browser.
|-
 
! {{chead}} width="150" | Software
 
! {{chead}} | Usage
 
|-
 
| [[OpenSSL]] || the standard encryption library from OpenSSL.org
 
|-
 
| [[OpenLDAP]] || the standard Lightweight Directory Access Protocol Directory from OpenLDAP.org
 
|-
 
| [[Cyrus-SASL]] || the RFC 2222 Secure Authentication Security Layer software from the Carnegie Mellon University
 
|-
 
| [[Sendmail]] || the legacy MTA software from Sendmail.org, reknown as complex to configure, but still widely used and released with many Linux distributions
 
|-
 
| [[Cyrus-IMAP]] || the industrial-grade POP/IMAP Server from the Carnegie Mellon University. Store the messages in a DB4 database, includes support for hierarchical folders, shared folders, and mail quotas
 
|-
 
| [[SpamAssassin]] || the well-known heuristic AntiSpam software, and other useful PERL scripts and programs
 
|-
 
| [[ClamAV]] || a Mail Antivirus for Sendmail and other MTAs
 
|-
 
| [[Milter]] || a Sendmail subsystem to allow mail filtering by third-party software as part of the Sendmail MTA mail processing
 
|-
 
| [[MIMEDefang]] || a third-party mail filtering software, affords using SpamAssassin and Clamav to filter mail as part of the Sendmail MTA mail processing
 
|-
 
| [[MySQL]] || the traditional companion to Apache and PHP. apr and apr-util, used by apache, refer to mysql so the latter must be installed first
 
|-
 
| [[Apache]] || the most widespread and Open Source HTTP server
 
|-
 
| [[PHP]] || a C-like scripting language well suited for Web development
 
|-
 
| [[phpMyAdmin]] || a PHP application to administrate MySQL databases
 
|-
 
| [[MediaWiki]] || a PHP application to manage Wikipedia Wikis
 
|-
 
| [[RoundCube]] || a PHP Webmail application
 
|-
 
| [[INN]] || Newsgroups server
 
|-
 
| [[Sucknews]] || Sucknews affords getting the newsfeeds over a regular NNTP connection with your Internet Service Provider when you have no agreements with peer Newsgroup servers
 
|-
 
| [[Asterisk]] || VoiP telephony server
 
|}
 
  
<br clear=all>
+
To invoke MySQL, use '''mysql -u user''' then enter queries at the mysql> prompt, '''quit''' to terminate the invocation. Commands can be entered uppercase or lowercase. It is possible to enter formulas, for example '''select sin(pi()/4), (4+1)*5, current_date;. "\c"''' at the end of a command affords cancelling.
  
== [[Desktop software]] ==
+
Queries may be entered on several lines. When awaiting input on a new line, mysql displays '''->''' if a command completion is awaited, '''<nowiki>'></nowiki> for a string that began with a '''<nowiki>'</nowiki>, '''“>''' for a string that began with a '''“''', '''`>''' for an identifier that began with a '''`''', '''/*>''' for a comment that began with a '''/*'''.
  
We use :
+
'''show databases;''' to view a list of existing databases. '''use database''' (without a semicolon) to use a specific database. GRANT ALL ON database.* TO 'your_mysql_name'@'your_client_host'; must have been used first by the admin to grant access. '''CREATE DATABASE database;''' to create a database then '''USE database'''.
  
{| {{thead}}
+
Alternatively it is possible to specify the database name as the last parameter on the mysql command eg '''mysql -h host -u user -p database. select database();''' affords viewing which database is in use.
|-
 
! {{chead}} width="150" | Software
 
! {{chead}} | Usage
 
|-
 
| [[Desktop software#Firefox|Firefox]] || web browser
 
|-
 
| [[Desktop software#Flashplayer|Flashplayer]] || animation plugin
 
|-
 
| [[Desktop software#Stellarium|Stellarium]] || planetarium software
 
|-
 
| [[Desktop software#Thunderbird|Thunderbird]] || mail client
 
|-
 
| [[Desktop software#VirtualBox|VirtualBox]] || virtualizer
 
|-
 
| [[Desktop software#Wallpapers|Wallpapers]] || just wallpapers
 
|-
 
| [[Desktop software#Wireshark|Wireshark]] || protocol analyzer
 
|}
 
  
<br clear=all>
+
<br/>
  
{{ pFoot |||[[Choosing a System]]}}
+
{{pFoot|[[Milter]]|[[Main Page]]|[[Apache]]}}

Latest revision as of 23:33, 6 December 2017

What is MySQL ?

MySQL is the traditional Database software companion to Apache and PHP. MySQL was previously a property of MySQL AB but was acquired by Oracle Corporation in 2010. This created some worries in the OpenSource community, which led to create a fork, MariaDB, which is a plug-in replacement for MySQL and the one included in the Slackware distribution.

Installing MySQL

The quickest way to install MySQL is to NOT install it and use instead MariaDB, included with Slackware. If this is your choice, please note that /usr will be the root directory of the software instead of /usr/local/mysql, and proceed to Running SQL.

apr and apr-util, used by apache, refer to MySQL so the latter must be installed first. Download the latest stable version, choosing "Source Code" when asked to Select platform. Documentation is available from the web site. Here MySQL is compiled with OpenSSL support to be able to encrypt MySQL connections on port 3306 (just in case, as we don't intend to open port 3306 to the external world at the moment).

# groupadd mysql
# useradd -g mysql mysql
# tar -C /usr/local -xvf mysql-x.y.z.tar.gz
# cd /usr/local/mysql-x.y.z
# chown -R root:root .
# less INSTALL-SOURCE
# rm CMakeCache.txt
# make clean
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DINSTALL_LIBDIR=lib64 \
-DINSTALL_PLUGINDIR=lib64/plugin -DMYSQL_DATADIR=/var/lib/mysql \
-DDEFAULT_CHARSET=latin1 -DDEFAULT_COLLATION=latin1_swedish_ci \
-DMYSQL_UNIX_ADDR=/var/run/mysql/mysql.sock -DWITH_SSL=yes
# make
# removepkg /var/log/packages/mysql-5.1.46-x86_64-2
# make install
# make clean
# cp -R /usr/local/mysql/man /usr/local
# cp support-files/my-default.cnf /etc/my.cnf
# chmod u+x scripts/mysql_install_db
# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/var/lib/mysql

Configuring MySQL

MySQL (5.6.24) works correctly out of the box so there is nothing to do really. In the past we had to edit /etc/my.cnf to uncomment line #skip-networking to prevent MySQL network connections. We also had to include in this file, after the [client] tag a line default-character-set=charset_name (for instance utf8 or latin1) to eliminate this warning when launching a client :

# mysql -u root -p
Enter password: 
mysql: Unknown OS character set 'ISO-8859-15'.
mysql: Switching to the default character set 'latin1'.
Welcome to the MySQL monitor.  Commands end with ; or \g.
. . .

This is no longer necessary, so let us directly update /etc/rc.d/rc.mysqld with new paths and options :

# Start mysqld:
mysqld_start() {
  if [ -x /usr/local/mysql/bin/mysqld_safe ]; then
    # If there is an old PID file (no mysqld running), clean it up:
    if [ -r /var/run/mysql/mysql.pid ]; then
      if ! ps axc | grep mysqld 1> /dev/null 2> /dev/null ; then
        echo "Cleaning up old /var/run/mysql/mysql.pid."
        rm -f /var/run/mysql/mysql.pid
      fi
    fi
    /usr/local/mysql/bin/mysqld_safe --character_set_server=utf8 \
        --basedir=/usr/local/mysql --datadir=/var/lib/mysql \
        --pid-file=/var/run/mysql/mysql.pid $SKIP &
  fi
}

Running SQL

Give execution rights to the rc.mysqld script and launch the daemon :

# chmod u+x /etc/rc.d/rc.mysqld
# /etc/rc.d/rc.mysqld start

Using MySQL

For a quick introduction on MySQL refer to this overview. Otherwise, if you have time to invest, MySQL comes with a very exhaustive documentation, including a tutorial. A few quick notes however :

Mysql defines a root user without an initial password. mysqladmin makes is possible to specify one by typing /usr(/local/mysql)/bin/mysqladmin -u root -p password ‘new-password’. The old password is then requested. Type return (the old password is empty). From that point, the password will need to be specified for every client invocation, for example : "/usr(/local/mysql)/bin/mysql -u root -p mysql_db". "-p" with no value means that the password will be requested interactively. mysql_db is the database name. Not specifying the password on the command line affords avoiding potential disclosure to other users using ps.

You can use mysql to configure itself. Refer to the documentation for the SQL syntax, or use phpMyAdmin, a PHP application to manage MySql from your browser.

To invoke MySQL, use mysql -u user then enter queries at the mysql> prompt, quit to terminate the invocation. Commands can be entered uppercase or lowercase. It is possible to enter formulas, for example select sin(pi()/4), (4+1)*5, current_date;. "\c" at the end of a command affords cancelling.

Queries may be entered on several lines. When awaiting input on a new line, mysql displays -> if a command completion is awaited, '> for a string that began with a ', “> for a string that began with a , `> for an identifier that began with a `, /*> for a comment that began with a /*.

show databases; to view a list of existing databases. use database (without a semicolon) to use a specific database. GRANT ALL ON database.* TO 'your_mysql_name'@'your_client_host'; must have been used first by the admin to grant access. CREATE DATABASE database; to create a database then USE database.

Alternatively it is possible to specify the database name as the last parameter on the mysql command eg mysql -h host -u user -p database. select database(); affords viewing which database is in use.


Milter Main Page Apache