|

Sukuriame MySQL duomenu baze

Prisijungiame:

# mysql -u root -p

Sukuriame duomenu baze vardu testing:

mysql> CREATE DATABASE testing;

Sukuriame vartotoja test_user, kurio slaptazodis test_pass:

mysql> GRANT ALL PRIVILEGES ON testing.* TO [email protected] IDENTIFIED BY 'test_pass';

Galime suteikti tik ribotas privilegijas:

GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON testing.* TO [email protected] IDENTIFIED BY 'test_pass';

ARBA:

Sukuriame vartotoja:

GRANT USAGE ON *.* TO <username>@localhost IDENTIFIED BY '<password>';

priskiniame duomenu bazei:

GRANT ALL PRIVILEGES ON <database_name>.* TO <username>@localhost;

Visa tai atlikus:

FLUSH PRIVILEGES;

Tikriname:

mysql -u<username> -p<password> <database>

Galima tai sukurti automatizuotai, naudojant skripta. Sukuriame faila, pvz. createdb, kurio turinys:

#!/bin/bash

EXPECTED_ARGS=3
E_BADARGS=65
MYSQL=`which mysql`

Q1="CREATE DATABASE IF NOT EXISTS $1;"
Q2="GRANT USAGE ON *.* TO [email protected] IDENTIFIED BY '$3';"
Q3="GRANT ALL PRIVILEGES ON $1.* TO [email protected];"
Q4="FLUSH PRIVILEGES;"
SQL="${Q1}${Q2}${Q3}${Q4}"

if [ $# -ne $EXPECTED_ARGS ]
then
echo "Usage: $0 dbname dbuser dbpass"
exit $E_BADARGS
fi

$MYSQL -uroot -p -e "$SQL"

Kaip naudotis? Komandineje eiluteje irasome:

createdb <database> <user> <password>
Kviečiu įvertinti įrašą!
[Viso: 0 Vidurkis: 0]

Similar Posts

Parašykite komentarą

El. pašto adresas nebus skelbiamas.

Sauga: − 1 = 3