Sometimes moving a database file ( /var/lib/mysql/* ) breaks the records inside mysql's brain about what databases it had and what their tables were. If you did not use mysqldump to take backups, you are in trouble. Unfortunately if you do this, you have a long night ahead of you. However, help is at hand. A symptom of breaking Moodle in this way is you get this error: Config table does not contain version, can not continue, sorry. which means it cannot read the table mdl_config. The basic steps are: 1. Move your crashed/confused databases out the way so you don't break them further. 2. Recreate your mysql instance. 3. Recreate the databases and tables WITHOUT their contents (just the database names and table structures). 4. Tell mysql to forget their contents without using drop command (you use discard instead) 5. move your original db files back into place 6. Tell mysql to re-scan (import) the db files. 7. Create a timed script to run backups Here are...
Warning: this will delete ALL your databases. After running this script it will let you automatically run mysql without a password (as root). Note this is a security risk so do not run this on a production server. #!/bin/bash set -e # Function to remove MySQL and clean up remove_mysql() { echo "Removing MySQL server and packages..." sudo apt-get remove -y mysql-server mysql-client mysql-common echo "Removing MySQL directories..." sudo rm -rf /etc/mysql /var/lib/mysql /var/log/mysql /var/run/mysqld # Clean up any residual packages and update package info sudo apt-get autoremove -y sudo apt-get clean } # Function to ensure MySQL configuration file exists ensure_mysql_config() { if [ ! -f /etc/mysql/mysql.cnf ]; then echo "Creating MySQL configuration file..." echo "[client]" | sudo tee /etc/mysql/mysql.cnf ...
If mysql says you can't login as root but you have definitely got the right password and you have just installed it for the first time, it can be a nuisance. Do the below as user root. My suggestion is: 1. If you have existing databases, and want to keep them, back them up with mysqldump. mysqldump -u user_with_access -pPassword database_to_rescue > database_to_rescue.sql Assuming that you have at least one user account, e.g. "user_with_access", who can read the database called “database_to_rescue". 2. Erase the mysql directory and start over: service mysql stop rm -rf /var/lib/mysql/* 3. Re-run mysqld initialisation to set the password to blank: mkdir -p /var/run/mysqld chown -R /var/run/mysqld chmod 777 /var/run/mysqld # you can change this back to 755 later mysqld --initialize-insecure --user=mysql If it says it can't find the socket in /var/run/mysqld, repeat the commands mkdir-chown above. 4. It will then set up mysql from scratch w...
Comments
Post a Comment