Last active
November 23, 2021 17:44
-
-
Save edib/eab4d9b6bb61fcba5a1dc308e1182198 to your computer and use it in GitHub Desktop.
manage mysql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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