To jest stara wersja strony!
Zalogowanie się do MySQL za pomocą mysql:
<font> $ mysql -u mysql -p mysql Enter password: Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 28 Server version: 5.5.11-log PLD/Linux Distribution MySQL RPM
Copyright © 2000, 2010, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> </font>
W PLD administrator MySQL’a nazywa się mysql, w innych dystrybucjach może on się nazywać inaczej np: w Debianie będzie to root Stworzenie użytkownika na bazie danych:
<font> CREATE USER 'username'@'localhost' IDENTIFIED BY 'tajne_password'; </font>
Zmiana hasła dla użytkownika:
<font> UPDATE mysql.user SET Password=PASSWORD('nowe_tajne_password') WHERE User='username'; </font>
Usunięcie użytkownika z bazy danych:
<font> DROP USER 'username'@'localhost'; </font>
Stworzenie instancji na bazie danych:
<font> CREATE DATABASE dbname; </font>
Nadanie praw użytkownikowi do bazy danych:
<font> GRANT ALL PRIVILEGES ON dbname.* TO username@'localhost'; </font>
Tu mała uwaga: w MySQL’u użytkownik identyfikowany jest za pomocą nazwa@host, gdzie nazwa@’%’ nie jest równa nazwa@localhost, więc gdy nasz użytkownik będzie logował się z zewnątrz (z poza localhost) to musimy nadać jemu do tego uprawnienia:
<font> GRANT ALL PRIVILEGES ON dbname.* TO username@'%'; </font>
Gdy pierwszy raz nadawaliśmy użytkownikowi nazwa@’%’ uprawnienia to MySQL tak naprawdę stworzył tego użytkownika i trzeba jemu nadać też hasło:
<font> UPDATE mysql.user SET Password=PASSWORD('tajne_password') WHERE User='username'; </font>
To samo tyczy się usuwania, jeśli istnieje użytkownik name@localhost i name@’%’ podczas usuwania name@localhost użytkownik name@’%’ zostanie na bazie danych! Jeśli nie chcemy tego to też musimy go usunąć:
<font> DROP USER 'username'@'%'; </font>
Usunięcie instancji na bazie danych:
<font> DROP DATABASE dbname; </font>
Po nadaniu uprawnień należy odświeżyć uprawnienia komendą:
<font> FLUSH PRIVILEGES; </font>
Wyświetlenie listy użytkowników:
<font> mysql> select host, user from mysql.user; +———–+—————–+
host | user |
+———–+—————–+
% | ocs |
127.0.0.1 | mysql |
127.0.0.1 | mysql_sysadmin |
localhost | |
localhost | mysql |
localhost | mysql_sysadmin |
localhost | ocs |
localhost | pong |
+———–+—————–+ 8 rows in set (0.01 sec)
mysql> </font>
Wyświetlenie listy instancji bazodanowych:
<font> mysql> show databases; +——————–+
Database |
+——————–+
information_schema |
mysql |
ocsweb |
pong |
+——————–+ 4 rows in set (0.00 sec)
mysql> </font>