Showing posts with label MySQL. Show all posts
Showing posts with label MySQL. Show all posts

Wednesday, September 9, 2015

Converting/Exporting mixed encoding MySQL data to UTF8

I had to move an old MySQL database storing the info of a Greek website, and guess what; the default schema collation was latin1_swedish_ci and the charset latin1, the defaults of MySQL instance (which no one changes during installation) :/
The schema contained a mixture of tables, some of them in latin1_swedish_ci collation and some other with the proper UTF8 settings. Trying to export the data from either MySQL Workbench, phpMyAdmin and host's panel I was getting an ANSI encoded sql file. Normally, that's fine but if your data contains UTF8 characters (i.e. Greek letters) then you've got a problem.

Sunday, August 5, 2012

MySQL drop all tables that follow a pattern

Playing around with drupal I had to drop all tables that were created by a module. To do so I used the following chain of commands :
mysql -u your_user -D your_database_name -e "show tables" -s | 
  egrep "^Whatever_" | 
  xargs -I "@@" echo mysql -u your_user -D your_database_name -e "DROP TABLE @@"

This will print out all the shell commands to drop the tables beginning with "Whatever_" (note the ^ regex notation). If you want it to actually execute those commands, remove the word "echo".

Saturday, October 15, 2011

Create user and db in MySQL for various apps

Working on a portal which requires the integration of various opensource applications, I had to install quite a few systems that require mysql databases. In order to keep a safe separation between these systems, one should create different users that will have access only to the specific database. This is a simple way to prevent losing all your databases in case of  the mishap when an attack is successful on a system and sql commands pass directly to the database (sql injection etc). This is a how-to create the new user, the new database and set the requested permissions.

Wednesday, September 28, 2011

Reset mysql 5.1 root pass

I had to install a couple of dbs on a mysql server which refused to recognize me as its root… I kept receiving the following not-so-friendly message:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
As it turns out, something was messed up during the installation and mysql did not recognize the given root password (mistype perhaps?). Anyway, I had to reset the pass, and this is how I did it.