digitus wrote: And how to manage mysql i would like to do same with DB accounts
By default your MySQL system has a couple of highly privileged users who can read, write, damage and destroy ALL of your databases. That's usually less than desirable. Do NOT run your MySQL applications using a superuser ID.
If you've got phpmyadmin installed that gives you a nice "user friendly" way to manage stuff. You need to set a strong password for the superusers (don't hit the "debian-sys-maint" ID, or you WILL break your system). You need to avoid using the root (ALL PRIVILEGES) users for application access to application data. Look at security permissions for <Directory /usr/share/phpmyadmin> in your Apache2 config files. You will want to include something like
Code: Select all
Order deny,allow
Deny from all
allow from 192.168.xxx.xxx
DO NOT allow anyone outside of your LAN to access
http://piaddr/phpmyadmin - if you open that to the public network you will have the World of hackers knocking on your door trying to poison your database.
So create a new ID, create a database with the same name. So if we have an application called "foobar", that runs with a userid of "foobar" and a database (or database prefix) of "foobar". On a single self-contained system you can permit that to "localhost" only. The default is for MySQL to only bind to the local interface unless you change it in your /etc/mysql/*/*.cnf files.
What I then do is create a foobar.cnf file and a foobar.inc.php file in /usr/local/etc/foobar.
/usr/local/etc/foobar/foobar.cnf
Code: Select all
[client]
host = localhost
port = 3306
[foobarapp1]
database = foobar
user = foobar
password = supersecretpasswordhere
/usr/local/etc/foobar/foobar.inc.php
Code: Select all
<?php
$con = mysql_connect('localhost', 'foobar','supersecretpasswordhere');
if (!$con) {
die($msgid.'001T DB Connection Error: ' . mysql_error());
}
$dbsel = mysql_select_db('foobar', $con);
if (!$dbsel) {
die($msgid.'002T Can\'t use database foobar: ' . mysql_error());
}
?>
In perl programs I can use
Code: Select all
my $connect = DBI->connect("DBI:mysql:;mysql_read_default_file=/usr/local/etc/foobar/foobar.cnf;mysql_read_default_group=foobarapp1", undef, undef) or die "something went wrong ($DBI::errstr)";
In PHP programs I can use
Code: Select all
$msgid = "FOOBAR";
include_once('/usr/local/etc/foobar/foobar.inc.php');
That means you can store the password but it's in a place that's not directly accessible form your web server and you're not littering your code with passwords (which would be a monster PITA when you next need to change them).
You can then use
mysql -u foobar -p foobar # note that's -u userid -p (force password) database name
from a command line to run SQL to create your tables/indexes and other resources.