[2024-feb-29] Sad news: Eric Layton aka Nocturnal Slacker aka vtel57 passed away on Feb 26th, shortly after hospitalization. He was one of our Wiki's most prominent admins. He will be missed.

Welcome to the Slackware Documentation Project

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
howtos:databases:install_mysql_on_slackware [2012/09/26 02:35 (UTC)] – moved from the general howtos namespace mfillpothowtos:databases:install_mysql_on_slackware [2013/02/12 11:31 (UTC)] (current) – Layout changes (proper heading/enumeration) and use of correct english in the new UTF8 section. alienbob
Line 1: Line 1:
-<!-- Add your text below. We strongly advise to start with a Headline (see button bar above). -->+<!-- Reviewed 2012-01-05 mfillpot --> 
 +<!-- Reviewed 2012-02-12 alienbob -->
 ====== Install MySQL On Slackware ====== ====== Install MySQL On Slackware ======
  
-== INSTALL MySQL ==+===== Installing MySQL ===== 
 +Install MySQL from the official Slackware discs or using [[slackware:slackpkg|slackpkg]]. If you performed a full install of Slackware, then you already have MySQL on your computer.
  
-Install MySQL from the official Slackware discs or using [slackpkg].+===== Configuring MySQL =====
  
 +  - Create the needed database(s) and set their permissions properly \\ As root, run: <code>
 +root@darkstar# mysql_install_db --user=mysql
 +</code> The user specified by ''--user'' will own the database files, so it's important to set the right user here, otherwise MySQL won't be able to write to your databases. By default MySQL in Slackware runs as user "mysql", so that is the safe choice.
 +  - Enable execution of the //rc script// to start MySQL automatically on boot \\ //This is optional.// <code>
 +root@darkstar# chmod 755 /etc/rc.d/rc.mysqld
 +</code>
 +  - Enable networking if needed \\ Networking is disabled by default to improve security. If you want to allow network connections, comment out this line in ''/etc/rc.d/rc.mysqld'': <file sh rc.mysqld>
 +#SKIP="--skip-networking"
 +</file>
 +  - Start mysqld <code>
 +root@darkstar# /etc/rc.d/rc.mysqld start
 +</code> and proceed to the next section "Securing MySQL".
  
-== CONFIGURE MySQL ==+===== Securing MySQL =====
  
-1) Create the needed database(s) and set their permissions properly. As root, run:+<note>You have a choice Manual or Automatic configuration of secure access</note>
  
-     mysql_install_db --user=mysql+==== Automatic configuration of secure access ==== 
 +  - Run the following command, and answer the questions <code> 
 +root@darkstar# /usr/bin/mysql_secure_installation 
 +</code> // The initial root password is "" (the empty string), so just hit <key>ENTER</key> when the above command asks for the password//
  
-User specified by ''--user'' will own database files, so it's important to set right user here, otherwise MySQL won't be able to write to database. By default MySQL in Slackware runs as user "mysql", so it's safe choice.   +==== Manual configuration of secure access ====
  
-2) Enable execution of rc script to start MySQL automatically on boot:+  - Set a password for MySQL's root account <code> 
 +root@darkstar# mysqladmin -u root password 'new-password-here' 
 +</code> If you enabled networking, you should also run this command<code> 
 +root@darkstar# mysqladmin -u root -h 'your-hostname' password 'new-password' 
 +</code> 
 +<note tip> 
 +Check the ''mysql_install_db'' results, these commands are printed, you can copy/paste them. The hostname will already be replaced by yours. 
 +</note>
  
-     chmod 755 /etc/rc.d/rc.mysqld+===== Connecting to your MySQL server =====
  
-3) Enable networking if needed+  - Connect to your MySQL server using the following command <code> 
 +user@darkstar$ mysql -u root -p 
 +</code> 
 +  - For security reasons you should delete the anonymous user 
 +    * For the localhost server: <code> 
 +mysql> use mysql 
 +mysql> SELECT user, host FROM user; 
 +mysql> DELETE FROM user WHERE host='localhost' AND user=''; 
 +</code> 
 +    * If you enabled networking, you should run this command instead: <code> 
 +mysql> use mysql 
 +mysql> SELECT user, host FROM user; 
 +mysql> DELETE FROM user WHERE user=''; 
 +</code>
  
-Networking is disabled by default to improve security. If you want to allow network connections, comment out this line in /etc/rc.d/rc.mysql +==== Adding Unicode support ==
-     #SKIP="--skip-networking" +
-  +
-4) Start mysqld:+
  
-     /etc/rc.d/rc.mysqld start+  - Change directory to the ''/etc/'' directory, and select the configuration which you preferFor a "simple" database service without heavy MySQL load, it is recommended to use "''my-large.cnf''" if you have 2 GB of RAM or more. Copy the configuration file you chose and name the copy ''/etc/my.cnf''
 +  - Edit ''/etc/my.cnf'' adding these lines in the section "''[mysqld]''": <code> 
 +[mysqld] 
 +collation-server = utf8_unicode_ci 
 +init-connect='SET NAMES utf8' 
 +character-set-server = utf8 
 +</code> This gives you full UTF8 support in your MySQL server, after you restarted it.
  
-//NOW YOU HAVE A CHOICE - MANUAL INSTALL OR AUTOMATIC//+More on Unicode UTF8 character set support is described here: [[http://stackoverflow.com/questions/3513773/change-mysql-default-character-set-to-utf8-in-my-cnf]]
  
-AUTOMATIC:+===== Troubleshooting =====
  
-5) 6) 7) Run the following, answer the questions:+  * Server start errors can be seen in the error log that is located by default at ''/var/lib/mysql/<hostname>.err''. Another option is to run the server directly and direct the output to the console (use <key>C-\</key> to stop the server). Run<code> 
 +root@darkstar# /usr/bin/mysqld_safe --console 
 +</code>
  
-     /usr/bin/mysql_secure_installation +  * Resetting the root password can be done by creating a new cnf file and add the following lines (please change the password in this example): <file sql mysql_new.cnf> 
-          Initial root password is "" so, just hit <ENTER> +UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root'; 
- +FLUSH PRIVILEGES; 
-MANUAL: +</file> Save this file (any name would do) and start the server with the --init-file argument: <code> 
- +root@darkstar# /usr/bin/mysqld_safe --defaults-file="new_cnf_file.cnf" 
-5) Set a password for MySQL's root password: +</code>
- +
-     mysqladmin -u root password 'new-password-here' +
- +
- +
-6) You can connect to your MySQL server with: +
-     mysql -u root -p +
- +
- +
-7) For security reasons you should delete an empty user for localhost server +
- +
-     mysql> use mysql +
-     mysql> SELECT user, host FROM user; +
-     mysql> DELETE FROM user WHERE host='localhost' AND user=''; +
- +
-== TROUBLESHOOTING == +
-1) Server start errors can be seen in the error log that is located by default at ''/usr/lib/mysql/<hostname>.err''. Another option is to run the server directly and direct the output to the console: +
-   +
-  /usr/bin/mysqld_safe --console +
-   +
-Resetting the root password can be done by creating a new cnf file and add the following lines (please change the password in this example): +
-   +
-  UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root'; +
-  FLUSH PRIVILEGES; +
- +
-Save this file (any name would do) and start the server with the --init-file argument: +
-   +
-  /usr/bin/mysqld_safe --defaults-file="new_cnf_file.cnf" +
-  +
  
 ====== Sources ====== ====== Sources ======
Line 78: Line 92:
  
 <!-- Please do not modify anything below, except adding new tags.--> <!-- Please do not modify anything below, except adding new tags.-->
-<!-- You must remove the tag-word "template" below before saving your new page --> +{{tag>howtos software mysql database author_arfon needs_content}}
-{{tag>howtos software mysq author_arfon}}+
 howtos:databases:install_mysql_on_slackware ()