MySQL

From Liki

Jump to: navigation, search

From wikimedia:

Check and see if the database server is running ("/usr/local/mysql/bin/mysqladmin status"), If not, sudo /usr/local/mysql/bin/safe_mysqld &.

Set a password for the "root" account on your database server. /usr/local/mysql/bin/mysqladmin -u root password yourpassword

Set up a user in MySQL for your Wiki--do this in your terminal: /usr/local/mysql/bin/mysql -u root -p mysql

This starts up the MySQL command line client. Now, do this in the client:

>grant select, insert, update, delete, lock tables on wiki.* to wiki@localhost identified by 'password';
>create database wiki;
>\q

To create a user and grant all priviledges on a database:

>GRANT ALL PRIVILEGES ON <db name>.* TO 'user'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
>\q

Typical Stuff

If the user forgets their password, login as root and use,

mysql> SET PASSWORD FOR username@localhost=PASSWORD('new_password');

Upgrade

Upgraded the server and the wikis crashed. Even the passwords were lost. Here is the fix:

The upgrade was to Fedora Core 6.

Firstly, SE Linux stuff for Fedora users:

cd /home/httpd/html.prod/wiki; ls -aZ; 
chcon -R system_u:object_r:httpd_sys_content_t wiki

Since we've lost the passwords, we must trick it to let us do what we have to do without passwords.

/etc/rc.d/init.d/mysqld stop 
/usr/libexec/mysqld --skip-grant-tables -u root
mysql_upgrade 

Now login...it will ask for a password but just hit enter. While you are at it, repair the index tables.

mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 5.0.22

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> UPDATE mysql.user SET Password=PASSWORD(''your password'')
    -> WHERE User='root';
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2  Changed: 2  Warnings: 0

mysql> use wiki
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> REPAIR TABLE searchindex;
+------------------+--------+----------+----------+
| Table            | Op     | Msg_type | Msg_text |
+------------------+--------+----------+----------+
| wiki.searchindex | repair | status   | OK       | 
+------------------+--------+----------+----------+
1 row in set (0.06 sec)
Personal tools