Installation MySQL

Auf meinem Basis-Server installiere ich nur den MySQL Client. Wenn Du den Server Installieren möchtest, kannst Du gleich runterscrollen zur Server installation. Der Client wird dann automatisch mitinstalliert.

MySQL Client

cd /usr/ports/databases/mysql55-client/
make install clean
   lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
   x Options for mysql-client 5.5.20                                    x
   x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x
   x x          [*] OPENSSL  Enable SSL support                       x x
   x x          [ ] FASTMTX  Replace mutexes with spinlocks           x x
   x mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x
   tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
   x                   <  OK  >                                 x
   mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj

 

MySQL Server

Anpassung von /etc/make.conf

In der Datei /etc/make.conffolgendes eintragen:

vi /etc/make.conf
#-----------------------------------------------#
#       MySQL                                   #
#-----------------------------------------------#
BUILD_OPTIMIZED=yes
WITH_PROC_SCOPE_PTH=yes
BUILD_STATIC=yes

DB_DIR wird mit aktuelleren Versionen nicht mehr benutzt – stattdessen wird im /etc/rc.conf die Variable mysql_dbdir definiert.

Anpassung von /etc/rc.conf

vi /etc/rc.conf
#-----------------------------------------------#
#       Database Server (MySQL)                 #
#-----------------------------------------------#
mysql_dbdir="/database"
mysql_enable="YES"

Installation

cd /usr/ports/databases/mysql55-server/
make install clean

Optionen:

lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
x Options for mysql-server 5.5.20                                    x
x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x
x x          [*] OPENSSL  Enable SSL support                       x x
x x          [ ] FASTMTX  Replace mutexes with spinlocks           x x
x mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x
tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
x                   <  OK  >                                 x
mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj

Konfiguration /etc/my.cnf

MySQL Optionen lassen sich via /etc/my.cnf konfigurieren. Nun noch die Log-Verzeichnisse erstellen

mkdir /var/log/mysql
chown mysql:mysql /var/log/mysql/

MySQL Server starten

Sobald der MySQL Server gestartet wird, werden die erstern notwenigen Datenbanken erstellt und der Server ist nun lauffähig.

/usr/local/etc/rc.d/mysql-server start

Berechtigungen anpassen

mysqladmin -u root password newpassword

Connecte zu mysql DB

mysql -uroot -p mysql
mysql> select * from user;

Hier werden nun alle Zugänge aufgelistet. Nun noch alle Passworte setzen:

mysql> update user set Password=password('newpassword') where User = 'root';

Anschliessen die test Datenbank löschen:

mysqladmin -u root -p  drop test 
Enter password: 
Dropping the database is potentially a very bad thing to do.
Any data stored in the database will be destroyed.

Do you really want to drop the 'test' database [y/N] y
Database "test" dropped

Und ebenfalls die entsprechenden Berechtigungen rauslöschen

mysql -u root -p mysql

Enter password: 
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 17 to server version: 4.1.11

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> delete from db WHERE Db='test';
Query OK, 1 row affected (0.00 sec)

mysql> delete from db WHERE Db='test\_%';
Query OK, 1 rows affected (0.00 sec)

Eventuell noch einen PowerUser erstellen, der von anderen Hosts aus arbeiten kann:

mysql -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 18 to server version: 4.1.11

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> GRANT ALL ON *.* TO 'myusername'@'%' IDENTIFIED BY 'anotherpassword';

Nach Anpassungen an den den Berechtigungen muss man die Privilegien-Datenbank neu laden um die Änderungen wirksam zu machen:

mysqladmin -u root -p flush-privileges 
Enter password:

Fehlermeldungen

/usr/local/libexec/mysqld: File ‚/var/log/mysql/mysql-bin.index‘ not found (Errcode: 13)

File konnte nicht erstellt werden. Check die Permissions:

chown -R mysql:mysql /var/log/mysql

mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication mysqlnd

Das Problem ist hier, dass noch alte Passwort in der mysql user DB gespeichert sind. mysql> select `User`,`Password` from user;

mysql> select `User`,`Password` from user;
+----------------+-------------------------------------------+
| User           | Password                                  |
+----------------+-------------------------------------------+
| user1          | 651632e76a6bcd0a                          |
| user2          | *3B88148F0D2F695B165DA6BBC7586C3AEB99F42E |
| user3_etc      | *E49B5939775BAE27032247BE8201FFE9C87AD6AE |

Die Passworte haben also zu wenig Zeichen. Somit müssen alle PWs geupdated werden, die noch insecure sind. Halt alle einzeln…

update user SET `Password` = PASSWORD('oldpassword') where `User` LIKE 'username';
FLUSH Privileges;

120525  6:13:16  InnoDB: Error: Write to file ./ib_logfile0 failed at offset 0 34504192.

Während einem DB-Backup ist die Datenbank gecrashed. Wegen zu hohem I/O. Log File während dem Crash:

120525  6:13:16  InnoDB: Error: Write to file ./ib_logfile0 failed at offset 0 34504192.
InnoDB: 1536 bytes should have been written, only -1 were written.
InnoDB: Operating system error number 5.
InnoDB: Check that your OS and file system support files of this size.
InnoDB: Check also that the disk is not full or a disk quota exceeded.
InnoDB: Error number 5 means 'Input/output error'.
InnoDB: Some operating system error numbers are described at
InnoDB: http://dev.mysql.com/doc/refman/5.5/en/operating-system-error-codes.html
120525  6:13:16  InnoDB: Assertion failure in thread 35424589824 in file fil0fil.c line 4492
InnoDB: Failing assertion: ret
InnoDB: We intentionally generate a memory trap.
InnoDB: Submit a detailed bug report to http://bugs.mysql.com.
InnoDB: If you get repeated assertion failures or crashes, even
InnoDB: immediately after the mysqld startup, there may be
InnoDB: corruption in the InnoDB tablespace. Please refer to
InnoDB: http://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-recovery.html
InnoDB: about forcing recovery.
04:13:16 UTC - mysqld got signal 6 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help
diagnose the problem, but since we have already crashed,
something is definitely wrong and this may fail.

key_buffer_size=268435456
read_buffer_size=1048576
max_used_connections=91
max_threads=1024
thread_count=5
connection_count=5
It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 3419240 K  bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

120525 06:13:17 mysqld_safe mysqld restarted
120525  6:13:17 InnoDB: The InnoDB memory heap is disabled
120525  6:13:17 InnoDB: Mutexes and rw_locks use GCC atomic builtins
120525  6:13:17 InnoDB: Compressed tables use zlib 1.2.5
120525  6:13:17 InnoDB: Initializing buffer pool, size = 500.0M
120525  6:13:17 InnoDB: Completed initialization of buffer pool
InnoDB: Error: tried to read 16384 bytes at offset 0 0.
InnoDB: Was only able to read -1.
120525  6:13:17  InnoDB: Operating system error number 5 in a file operation.
InnoDB: Error number 5 means 'Input/output error'.
InnoDB: Some operating system error numbers are described at
InnoDB: http://dev.mysql.com/doc/refman/5.5/en/operating-system-error-codes.html
InnoDB: File operation call: 'read'.
InnoDB: Cannot continue operation.
120525 06:13:17 mysqld_safe mysqld from pid file /database/tesla.shoe.org.pid ended

Wie gesagt, das Problem war, dass durch das Backup die HDD Probleme machte. Das Problem mit der Harddisk hab ich hier separat behandelt.

Nun ist das Problem, dass InnoDB die Recovery nicht sauber hingekriegt hat. Bei meinem manuellen Restart kamen dann diese Fehlermeldungen:

120525  8:42:07  InnoDB: Waiting for the background threads to start
120525  8:42:08 InnoDB: 1.1.8 started; log sequence number 25804223021
120525  8:42:08  InnoDB: Assertion failure in thread 34397535232 in file fut0lst.ic line 83
InnoDB: Failing assertion: addr.page == FIL_NULL || addr.boffset >= FIL_PAGE_DATA
InnoDB: We intentionally generate a memory trap.
InnoDB: Submit a detailed bug report to http://bugs.mysql.com.
InnoDB: If you get repeated assertion failures or crashes, even
InnoDB: immediately after the mysqld startup, there may be
InnoDB: corruption in the InnoDB tablespace. Please refer to
InnoDB: http://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-recovery.html
InnoDB: about forcing recovery.

Leider lässt sich eine InnoDB Table nicht so einfach repairen. Aber ich mach ja zum Glück regelmässig Backups. Gelöst hab ich das Problem nun so:

  1. Zuerst einfach mal alle Webserver stoppen, damit nicht weiter auf MySQL zugegriffen werden kann. 
  2. /etc/my.cf anpassen und

    [mysqld]
    innodb_force_recovery = 5

    hinzufügen. Weitere Infos zu den forcing-innnodb-recovery Settings gibts hier.
  3. Nun kann man mysql starten. Man kann nun SELECTEN, DROP oder CREATEn.
  4. Jetzt alle InnoDB Tables auflisten:

    SELECT table_schema, table_name FROM INFORMATION_SCHEMA.TABLES WHERE engine = ‚innodb‘;
  5. Jetzt alle diese InnoDB Tables backupen. Am Besten dies gleich mit einem Shell Script machen.
  6. Danach alle InnoDB Tables löschen. Kann man auch so machen (nachdem man mysql gestoppt hat):

    rm -rf /database/*/*.ibd 
  7. nun mysql stoppen
  8. alle /database/ib_logfiles sowie ibdata LÖSCHEN!
  9. nun gibt es keine InnoDB Files mehr.
  10. Nun im

    /etc/my.cf

    innodb_force_recovery = 0

    Wieder auf 0 setzen und mysql neu starten.
  11. Sollte nun wieder alles ohne Probleme laufen. Ev. Optimize / Repair Table machen für die restlichen Probleme.
  12. Nun alle InnoDB Backups zurückladen.
  13. Am Ende zur Sicherheit Mysql neu starten.
  14. Jetzt läuft wieder alles. Nginx nicht vergessen neu zu starten! PHP-FPM ev. auch noch.

Weitere Infos dazu:

MySQL Upgraden

Achtung! Bei Upgrades immer vorher die Datenbank Backupen mit MysqlDUMP! /usr/local/bin/mysqldump –all -c –add-drop-table -Q -uroot -p -hlocalhost $DB >> $MYSQLBDIR/$DB/DUMP_$DATE.txt Bei kleinen Versions-Upgrades, reicht ein

portupgrade mysql-client-5.0.15
portupgrade mysql-server-5.0.15

Nach dem Upgrade von mysql-client sollte alles so weiterlaufen wie bisher (web etc.) Nach dem Install vom mysql-server muss Service neu gestartet werden -> Web lauft sonst nicht mehr!um eben z.b. auf vers 5.0.20 zu upgraden. Wechselt die Version komplett, wie folgt vorgehen: Wenn man auf die nächste Version upgraden will, kommt die Fehlermeldung:

===>  mysql-server-5.0.15 is marked as broken: MySQL versions mismatch: mysql41-client is installed and wanted version is mysql50-client.

Weil man nicht 2 Versionen gleichzeitig laufenlassen kann. Jetzt muss man zuerst bei der neuen Version das MAKE forcieren:

root@corky(/usr/ports/databases/mysql50-server)> make -DTRYBROKEN

kann aber sein, dass das auch nicht funktioniert:

===>  Installing for mysql-client-5.0.15

===>  mysql-client-5.0.15 conflicts with installed package(s): 
      mysql-client-4.1.14 

      They install files into the same place.
      Please remove them first with pkg_delete(1).
*** Error code 1 

Stop in /usr/ports/databases/mysql50-client.
*** Error code 1 

Stop in /usr/ports/databases/mysql50-server.

Sobald es kompiliert ist, die alte Version deinstallieren Shutdown Mysql Server

/usr/local/etc/rc.d/mysql-server.sh stop
cd /usr/ports/databases/mysql41-server/
make deinstall
cd /usr/ports/databases/mysql41-client/
make deinstall

Jetzt neue Version installieren:

cd /usr/ports/databases/mysql50-server
make WITH_PROC_SCOPE_PTH=yes install

Hinweis: Um zu sehen, mit welchen Optionen man mysql installieren kann, folgenden Befehl benutzen:

make pre-fetch

You may use the following build options:
       WITH_CHARSET=charset    Define the primary built-in charset (latin1).
       WITH_XCHARSET=list      Define other built-in charsets (may be 'all').
       WITH_COLLATION=collate  Define default collation (latin1_swedish_ci).
       WITH_OPENSSL=yes        Enable secure connections.
       WITH_LINUXTHREADS=yes   Use the linuxthreads pthread library.
       WITH_PROC_SCOPE_PTH=yes Use process scope threads
                               (try it if you use libpthread).
       BUILD_OPTIMIZED=yes     Enable compiler optimizations
                               (use it if you need speed).
       BUILD_STATIC=yes        Build a static version of mysqld.
                               (use it if you need even more speed).
       WITHOUT_INNODB=yes      Disable support for InnoDB table handler.
       WITH_ARCHIVE=yes        Enable support for Archive Storage Engine.
       WITH_NDB=yes            Enable support for NDB Cluster.

Upgrade Regeln

Bei Upgrades von Releasen (also 5.0 auf 5.1 oder 4.0 auf 5.0 etc. – nicht 5.04 auf 5.05) ist folgendes wichtig:

  • Wenn Sie in Bezug auf neue Versionen eher vorsichtig sind, können Sie Ihr vorhandenes mysqld immer umbenennen, bevor Sie eine neue Version installieren. Verwenden Sie beispielsweise MySQL 5.0.13 und wollen auf 5.1.10 aktualisieren, dann benennen Sie Ihren aktuellen Server von mysqld zu mysqld-5.0.13 um. Tut Ihr neuer Server mysqld dann etwas Unerwartetes, dann können Sie ihn einfach herunterfahren und mit Ihrem alten mysqld neu starten.

Upgrade Manuals genau durchlesen:

Wichtig, bei der deinstallation vom mysql-client immer notieren, welche Ports die mysqllib verwendet haben. also den Output

==>  Deinstalling for databases/mysql50-client
===>   Deinstalling mysql-client-5.0.90_2
pkg_delete: package 'mysql-client-5.0.90_2' is required by these other packages
and may not be deinstalled (but I'll delete it anyway):

apr-devrandom-gdbm-db43-mysql50-1.4.2.1.3.10

nagios-3.2.2_1
nagios-plugins-1.4.15_1,1
p5-DBD-mysql50-4.017
pecl-fileinfo-1.0.4
pecl-pdflib-2.1.8
pecl-runkit-0.9
php5-5.3.3_2
php5-calendar-5.3.3_2
php5-ctype-5.3.3_2
php5-curl-5.3.3_2
php5-dom-5.3.3_2
php5-extensions-1.4
php5-filter-5.3.3_2
php5-ftp-5.3.3_2
php5-gd-5.3.3_2
php5-hash-5.3.3_2
php5-imap-5.3.3_2
php5-json-5.3.3_2
php5-mbstring-5.3.3_2
php5-mcrypt-5.3.3_2
proftpd-mysql-1.3.3c_3
subversion-1.6.15
ap22-mod_limitipconn-0.23_2
ap22-mod_extract_forwarded-2.0.2_2
apache-2.2.17_1

zwischenspeichern, damit wir all diese Ports danach reinstallieren können.

make deinstall
make reinstall

Wenn eh gleich ein Port geupgraded werden muss, z.B. php, geht das auch einfach so

portupgrade -fpb php5\*

MySQL Optimierungen

  • *

    Du kannst diese HTML tags verwenden: <a> <abbr> <acronym> <b> <blockquote> <cite> <code> <del> <em> <i> <q> <s> <strike> <strong>

  • Kommentar-Feed für diesen Beitrag
nach oben