To jest stara wersja strony!
Zalogowanie się do MySQL za pomocą mysql:
$ 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 (c) 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>
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:
CREATE USER 'username'@'localhost' IDENTIFIED BY 'tajne_password';
Zmiana hasła dla użytkownika:
UPDATE mysql.user SET Password=PASSWORD('nowe_tajne_password') WHERE User='username';
Usunięcie użytkownika z bazy danych:
DROP USER 'username'@'localhost';
Stworzenie instancji na bazie danych:
<font> CREATE DATABASE dbname; </font>
Nadanie praw użytkownikowi do bazy danych:
GRANT ALL PRIVILEGES ON dbname.* TO username@'localhost';
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:
GRANT ALL PRIVILEGES ON dbname.* TO username@'%';
Gdy pierwszy raz nadawaliśmy użytkownikowi nazwa@’%’ uprawnienia to MySQL tak naprawdę stworzył tego użytkownika i trzeba jemu nadać też hasło:
UPDATE mysql.user SET Password=PASSWORD('tajne_password') WHERE User='username';
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ąć:
DROP USER 'username'@'%';
Usunięcie instancji na bazie danych:
DROP DATABASE dbname;
Po nadaniu uprawnień należy odświeżyć uprawnienia komendą:
FLUSH PRIVILEGES;
Wyświetlenie listy użytkowników:
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>
Wyświetlenie listy instancji bazodanowych:
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | ocsweb | | pong | +--------------------+ 4 rows in set (0.00 sec) mysql>