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
pkg install mysql81-client-8.1.0
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:
- Zuerst einfach mal alle Webserver stoppen, damit nicht weiter auf MySQL zugegriffen werden kann.
- /etc/my.cf anpassen und
[mysqld]
innodb_force_recovery = 5
hinzufügen. Weitere Infos zu den forcing-innnodb-recovery Settings gibts hier. - Nun kann man mysql starten. Man kann nun SELECTEN, DROP oder CREATEn.
- Jetzt alle InnoDB Tables auflisten:
SELECT table_schema, table_name FROM INFORMATION_SCHEMA.TABLES WHERE engine = ‚innodb‘; - Jetzt alle diese InnoDB Tables backupen. Am Besten dies gleich mit einem Shell Script machen.
- Danach alle InnoDB Tables löschen. Kann man auch so machen (nachdem man mysql gestoppt hat):
rm -rf /database/*/*.ibd - nun mysql stoppen
- alle /database/ib_logfiles sowie ibdata LÖSCHEN!
- nun gibt es keine InnoDB Files mehr.
- Nun im
/etc/my.cf
innodb_force_recovery = 0
Wieder auf 0 setzen und mysql neu starten. - Sollte nun wieder alles ohne Probleme laufen. Ev. Optimize / Repair Table machen für die restlichen Probleme.
- Nun alle InnoDB Backups zurückladen.
- Am Ende zur Sicherheit Mysql neu starten.
- Jetzt läuft wieder alles. Nginx nicht vergessen neu zu starten! PHP-FPM ev. auch noch.
Weitere Infos dazu:
- http://www.chriscalender.com/?p=514
- http://www.chriscalender.com/?p=355
- http://www.chriscalender.com/?p=49
- http://www.chriscalender.com/?tag=innodb-recovery
- http://www.chriscalender.com/?m=201112
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:
- Alte DBs backupen (inkl. der mysql db mit den privileges) http://dev.mysql.com/doc/refman/5.1/de/mysql-fix-privilege-tables.html
- Nie eine Version überspringen. D.h. wenn wir 5.0 haben und auf 6.0 upgraden wollen, müssen wir zuerst auf Vers. 5.1 upgraden und danach auf 6.0 http://dev.mysql.com/doc/refman/5.5/en/upgrading.html
- Wenn du in Bezug auf neue Versionen eher vorsichtig bist, kannst du dein vorhandenes mysqld immer umbenennen, bevor du eine neue Version installierst. Verwendest du beispielsweise MySQL 5.0.13 und möchtest auf 5.1.10 aktualisieren, dann benennst du deinen aktuellen Server von mysqld zu mysqld-5.0.13 um. Tut dein neuer Server mysqld dann etwas Unerwartetes, dann kannst du ihn einfach herunterfahren und mit deinem alten mysqld neu starten.
mysqld Binary Location:/usr/local/libexec/mysqld
Das hier ist nur der StartupScript (Backup nicht notwendig)/usr/local/bin/mysqld_safe
- Bei Replication immer zuerst den Slave auf die neuste Version upgraden und erst danach den Master. http://dev.mysql.com/doc/refman/5.1/de/replication-upgrade.html
Upgrade Manuals genau durchlesen:
- http://dev.mysql.com/doc/refman/5.1/de/upgrade.html
- http://dev.mysql.com/doc/refman/5.1/de/upgrading-from-5-0.html
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*
Upgrade Quick & Dirty
- Altes MySQL Binary backupen (xxx mit entsprechender Versionsnummer ersetzen):
cp /usr/local/libexec/mysqld /usr/local/libexec/mysqld-x-xx-xx
- Webserver in Maintenance Mode setzen:
cd /global/nginx_global_config
mv MAINTENANCE_OFF MAINTENANCE_ON - MySQL Server und alle anderen outdated Ports upgraden:
pkg unlock mysql55-server
alternativ nur mysql-server upgraden:
pkg upgradepkg install mysql55-server
- MySQL Server starten:
/usr/local/etc/rc.d/mysql-server start
- MySQL Upgrade laufen lassen:
mysql_upgrade --verbose --verbose -u root -p localhost
- Webserver wieder in den online Modus setzen:
cd /global/nginx_global_config
mv MAINTENANCE_ON MAINTENANCE_OFF - Port wieder locken, damit er nicht unvorbereitet upgraded:
pkg lock mysql55-server