Archive for the ‘MySql’ category

Adding a user to a MySql database

June 20th, 2008

Giving a user full permissions in MySql is pretty simply task, as long as you have access. To do so, all you need to do is log into the MySql server that the database is housed on/at. Once there enter MySql by typing;

mysql

In some cases, such as running a control panel, you will need to use the following syntax to apply a password;

mysql -uadmin -p  (it also might be mysql -uroot -p)

This should open a command prompt. Now you need to type;

GRANT ALL ON [database].* TO [username]@’%’ IDENTIFIED BY ‘[password]‘;

So basically substituting [database] with the database name, [username] with the person’s new username, [password] with the specified password. If you see no rows affected, replace [username]@’%’ with [username]@’localhost’  .

Then after this, type;

FLUSH PRIVILEGES;

Thats it! The user is added!

Upgrading Mysql on Linux (php)

March 14th, 2008

The easist way I’ve found to upgrade your existing Mysql install on a linux stall is to use Yum. If you do not have yum, you can follow this link to do this – http://www.keithdmitchell.com/archives/43 .

If you do have Yum installed, then all you need to do is log into the linux shell (SSH) and type at the command prompt;

yum update mysql

Yum will then start the Mysql upgrade process and will install the lastest version of Mysql. Make a backup of the system state or if this is a vps, backup the entire vps if you are not sure if you will want to stay at Mysql 5.

Grant remote access to a mysql database.

March 11th, 2008

If you are trying to access a mysql database and are rejected when you try to use a Mysql GUI tool, such as Mysql Front, chances are that this is due to the user only have access to local access. To create this, you will need to create the database and then assign it remote access.

For this example, I will create the database , testing. First you log into the mysql server locally. Then you create the database;

Mysql> Create database testing;

Now you will create the user, password and remote address.

Mysql> use database testing;

GRANT ALL ON testing.* TO admin@’56.56.2.2′ IDENTIFIED BY ‘PASSWORD‘;

This will create the user, password and grant remote access to the server. You will also want to create access for local access as well;

GRANT ALL ON testing.* TO admin@’127.0.0.1′ IDENTIFIED BY ‘PASSWORD‘;

OR

GRANT ALL ON testing.* TO admin@’localhost’ IDENTIFIED BY ‘PASSWORD‘;

That’s it!

Installing MySQL 4.1 PHP (Windows)

February 14th, 2008
  1. Download MySQL v4.1

    Download MySQL from http://dev.mysql.com/downloads/mysql/4.1.html Just make sure you get a Windows Essentials (x86) binary version. (after you click the “pick a mirror,” if it asks you to login, scroll down a little and click the “No thanks, just take me to the downloads!” link under the login form)

    My file was named: mysql-essential-4.1.22-win32.msi

  2. Install MySQL v4.1

    Run the MSI file and use the following settings

    • Typical Setup
    • Skip Sign-Up
    • make sure “Configure the MySQL Server now” is checked
    • “Detailed Configuration”
    • “Developer Machine”
    • “Multifunctional Database”
    • “InnoDB Tablespace Settings” – leave everything default
    • “Decision Support (DSS)/OLAP”
    • make sure “Enable TCP/IP Networking” is checked and leave the port number at 3306 (at this point, if you have a firewall, it will usually try to access itself on the localhost)
    • “Standard Character Set”
    • check “Install As Windows Service”
    • enter your root password and I would recommend leaving “Enable root access from remote machines” unchecked
    • then hit “execute” and it’ll install and set it up.
  3. Getting PHP5 to work with MySQL – Official Info

    Unfortunately PHP5 removed built-in support for MySQL. To get it to work, the easiest way is to copy the mysql library file by hand. Open the folder you unzipped your PHP to. Copy the libmysql.dll file (should be located like E:\php\libmysql.dll ) into your Window’s System folder (usually C:\Windows\System32\ although might be C:\WinNT\System\ or something).

    Then open up your php.ini in a text editor and search for ;extension=php_mysql.dll and remove the ; infont of that line.

    Restart Apache and see if you get any errors. If it complains about “php_mysql.dll” either your extension directory isn’t correct or windows can’t find libmysql.dll

  4. Testing MySQL

    Testing MySQL is not exactly easy. However, here are the common connection strings for PHP and CGI. I recommend downloading phpMyAdmin and using it to create and manage your databases, etc.

    PHP Connection test

    <?php
    // hostname or ip of server (for local testing, localhost should work)
    $dbServer='localhost';
    
    // username and password to log onto db server
    $dbUser='root';
    $dbPass='';
    
    // name of database
    $dbName='test';
    
        $link = mysql_connect("$dbServer", "$dbUser", "$dbPass") or die("Could not connect");
        print "Connected successfully<br>";
        mysql_select_db("$dbName") or die("Could not select database");
        print "Database selected successfully<br>";
    
    // close connection
    mysql_close($link);
    ?>

    CGI Connection test (Must have DBI module installed)

    #!/usr/bin/perl
    
    print "Content-type: text/htmlnn";
    
    # DBI is perl module used to connect to the database
    use DBI;								 
    
    # hostname or ip of server (for local testing, localhost should work)
    $config{'dbServer'} = "localhost";
    
    # username and password to log onto db server
    $config{'dbUser'} = "root";
    $config{'dbPass'} = "";			
    
    # name of database
    $config{'dbName'} = "test";			
    
    # MySQL driver (shouldn't need to change)
    $config{'dataSource'} = "DBI:mysql:$config{'dbName'}:$config{'dbServer'}";	
    
    my $dbh = DBI->connect($config{'dataSource'},$config{'dbUser'},$config{'dbPass'}) or
    die "Can't connect to $config{'dataSource'}<br>$DBI::errstr";
        print "Connected successfully<br>";
    $dbh->disconnect();

How can I change/repair my admin account if the password is lost?

January 29th, 2008

How can I change/repair my admin account if the password is lost?

Applies to Plesk for Linux/Unix

SYMPTOMS

If you see one of the following error messages:

Unable to connect to database

login.php3: Unable to connect to database: Permission denied

ERROR 1045: Access denied for user: ‘admin@localhost’ (Using password: YES)

Then we can offer you the following options to solve this issue. The example below is for RedHat-like operations systems (RedHat, CentOS, FedoraCore), for other operation systems paths to mysql binaries may differ.

RESOLUTION

1. Please try to restart Plesk first:

# /etc/init.d/psa restart

2. Make sure that /etc/psa/.psa.shadow file has a valid permissions. Right permissions should be

# ls -la /etc/psa/.psa.shadow
-rw------- 1 psaadm psaadm 5 Feb 26 11:22 /etc/psa/.psa.shadow

If you have any other permissions, then you need to change it using the following command:

# chown psaadm:psaadm /etc/psa/.psa.shadow
# chmod 600 /etc/psa/.psa.shadow

3. Make sure that Mysql server is running and working properly using the “ps ax | grep mysql” command. For example:

# ps ax | grep mysql
7996 ? S 0:00 /bin/sh /usr/bin/safe_mysqld --defaults-file=/etc/my.cnf
8022 ? S 0:14 /usr/libexec/mysqld --defaults-file=/etc/my.cnf --basedir=/usr
--datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-locking

If you see this output, then it means that Mysql server is running.

To check that Mysql server is working properly, you should try to log into mysql console. For example:

# mysql -uadmin -p`cat /etc/psa/.psa.shadow` -D psa
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 1299 to server version: 3.23.54

Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.

mysql>

Usually the error message presented below appears:

ERROR 1045: Access denied for user: ‘admin@localhost’ (Using password: YES)

If you cannot log into MySQL using command line above, then the following solution will help you to repair admin account password.

4. In the last Plesk versions the password can be reset using “ch_admin_passwd” utility.

# /usr/local/psa/admin/sbin/ch_admin_passwd --help
/usr/local/psa/admin/sbin/ch_admin_passwd: Utility to set Plesk adminstrator's password
Gets password from the environment variable PSA_PASSWORD
Password should be from 5 to 14 symbols and should not contain login name, whitespace, quotes or national characters

Usage: /usr/local/psa/admin/sbin/ch_admin_passwd

-h, –help
display this help and exit
To change the password use the command like:

# export PSA_PASSWORD='NEW_PASSWORD' ; /usr/local/psa/admin/sbin/ch_admin_passwd; unset PSA_PASSWORD

Where NEW_PASSWORD have to be replaced with your desired Plesk administrator password.

If there is no such utility in your Plesk version, the password can be synchronizes manually.

a) Load MySQL with the ’skip-grant-tables’ option by adding skip-grant-tables into [mysqld] section of the /etc/my.cnf file

b) Restart MySQL with the command line below:

# /etc/init.d/mysqld restart

c) Put the new password into /etc/psa/.psa.shadow file.

d) Repair password with the command line below:

# /usr/bin/mysql -D mysql -e"update user set password=PASSWORD('`cat /etc/psa/.psa.shadow`') where User='admin';"

e) Remove skip-grant-tables option from /etc/my.cnf

f) Restart MySQL.