Skip to content

Instantly share code, notes, and snippets.

@xeoncross
Created March 11, 2011 20:59
Show Gist options
  • Save xeoncross/866571 to your computer and use it in GitHub Desktop.
Save xeoncross/866571 to your computer and use it in GitHub Desktop.
MySQL snippets for backup, restore, users, statistics, etc..
# Import SQL file (those too big for phpMyAdmin
mysql -u username -p -h localhost database-name < data.sql
# Copy data from one table schema to another (useful when structure is similar between tables)
INSERT INTO table1 ( `username`, `email`, `password`, `firstname`, `lastname`, `created`)
SELECT `username`, `email`, `password`, `firstname`, `lastname`, UNIX_TIMESTAMP() FROM table2
# Make sure you set the RIGHT host when you create a new user (127.0.0.1 vs localhost vs an IP vs "%")
# Create new User and give them access to database
GRANT ALL ON demo.* TO user1@localhost IDENTIFIED BY 'mypassword';
# Give full access to a user
GRANT ALL PRIVILEGES ON *.* TO 'user'@'localhost' WITH GRANT OPTION;
# OR give full access to a user for a certain database
GRANT ALL PRIVILEGES ON databasename.* TO 'user'@'localhost' WITH GRANT OPTION;
# Change user password
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-PASSWORD-HERE") where User='tom';
# Change user hosts that can connect to all
mysql> use mysql;
mysql> update user set host='%' where user='username';
mysql> flush privileges;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment