Posts

Showing posts from April, 2021

what to do if you crashed your database OR it says there are no tables (but there are!)

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 the detailed st

commandline start mysql on mac

  $ sudo /usr/local/mysql/support-files/mysql.server start

reset root (overarching) password for mysql

mysqld --skip-grant-tables or sudo mysqld_safe --skip-grant-tables then mysql -u root mysql> FLUSH PRIVILEGES; mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword'; if this complains about permissions on the mac, try  sudo chown -R _mysql:staff /usr/local/mysql-5.7.22-macos10.13-x86_64/ sudo chmod -R 777 /usr/local/mysql-5.7.22-macos10.13-x86_64/data/ then  /usr/local/mysql/bin/mysqld_safe --skip-grant-tables or mysqld --skip-grant-tables if that doesn't work then try an init file: mysqld -- init-file =/var/lib/mysql/reset.txt  --user=mysql inside that reset.txt file put the "alter user" statement above. if that doesn't work then you have to really reset everything: warning, this WILL delete all your databases unless you back them up first. The commands below contain a backup. mysqldump -u root -p"myrootpassword"  mydatabase > /root/mydatabase.sql # make sure we move existing dbs out the way so they are safe mv /v

Create database syntax mysql

  When creating the app database, you need to set the owner. First, create the database. mysql> create database  appname ; then create the  user who will have write permissions: mysql> create user ' appname '@' localhost ' identified  with mysql_native_password  by ' somepassword '; mysql> flush privileges; If you forget the password, you can change it again like so: mysql> alter user ' appname'@'localhost'  identified  with mysql_native_password  by ' somepassword '; If you are using mysql version 8 or later, you need "with mysql_native_password" otherwise wordpress doesn't authenticate the database owner. At least, that was still true at the time of writing this. If you are using mysql version 5 or below, you can skip that. 

Grant permissions

 Login to mysql and run this, where "database" is your database, "username" is your database username, and "password" is your preferred password. grant all on database.* to 'username'@'localhost' identified with mysql_native_password by "password"; Note this is for mysql 8 and above, mysql 5 and below you remove the "with mysql_native_password" part.

Download URL mysql

   https://downloads.mysql.com/archives/community/

Permanently save login password for mysql client

 If you find it a nuisance to constantly type the mysql password while working with mysql, you can tell it to save, and thereafter it won't ask for it. WARNING. This exposes your database to hackers in that if they gain access to your account, your copy of mysql is also vulneralble. The command is: mysql_config_editor set --host=localhost --user=<whoever> --password

purpose of this blog

 The purpose of this blog is to save useful tips about mysql