Skip to content

Instantly share code, notes, and snippets.

@edib
Last active November 23, 2021 17:44
Show Gist options
  • Save edib/eab4d9b6bb61fcba5a1dc308e1182198 to your computer and use it in GitHub Desktop.
Save edib/eab4d9b6bb61fcba5a1dc308e1182198 to your computer and use it in GitHub Desktop.
manage mysql
# mysql reset root password
# run mysql in safe mode
sudo mysqld_safe --skip-grant-tables &
# unless if starts with following
#mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists
mkdir -p /var/run/mysqld
chown mysql:mysql /var/run/mysqld
# try again
# login as root
mysql -u root
#make password null
UPDATE mysql.user SET authentication_string=null WHERE User='root';
# flush
FLUSH PRIVILEGES;
exit;
mysql -u root
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'yourpasswd';
FLUSH PRIVILEGES;
# create user and db
# login as superuser
mysql -u root -p
# create a db
CREATE DATABASE some-db;
# create a user
CREATE USER 'some-user'@'localhost' IDENTIFIED WITH mysql_native_password BY 'some-strong-password';
# grant db owner
GRANT ALL PRIVILEGES ON some-db.* TO 'some-user'@'localhost';
# or grant some rights
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, INDEX, DROP, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON some-db.* TO 'some-user'@'localhost';
# or grant all (dangerous!)
GRANT FILE ON *.* TO 'some-user'@'localhost';
# flush
FLUSH PRIVILEGES;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment