Getting data for histogram plot

This is a post about a super quick-and-dirty way to create a histogram in MySQL for numeric values. There are multiple other ways to create histograms that are better and more flexible, using CASE statements and other types of complex logic. This method wins me over time and time again since it’s just so easy … Read more

How to find out the MySQL root password

thanks to @thusharaK I could reset the root password without knowing the old password. On ubuntu I did the following: sudo service mysql stop sudo mysqld_safe –skip-grant-tables –skip-syslog –skip-networking Then run mysql in a new terminal: mysql -u root And run the following queries to change the password: UPDATE mysql.user SET authentication_string=PASSWORD(‘password’) WHERE User=”root”; FLUSH … Read more

MySQL: Set user variable from result of query

Yes, but you need to move the variable assignment into the query: SET @user := 123456; SELECT @group := `group` FROM user WHERE user = @user; SELECT * FROM user WHERE `group` = @group; Test case: CREATE TABLE user (`user` int, `group` int); INSERT INTO user VALUES (123456, 5); INSERT INTO user VALUES (111111, 5); … Read more

How to connect to MySQL from the command line

See here http://dev.mysql.com/doc/refman/5.0/en/connecting.html mysql -u USERNAME -pPASSWORD -h HOSTNAMEORIP DATABASENAME The options above means: -u: username -p: password (**no space between -p and the password text**) -h: host last one is name of the database that you wanted to connect. Look into the link, it’s detailed there! As already mentioned by Rick, you can avoid … Read more