|
|
MySQLTable of contentsFrom WwwMy notes about using mysql. MySQL is *REALLY* picky about domain names. So if you change the name of your machine (or change domains or add a domain name) you will get looked out of your mysql server! So be REALLY careful when you are changing names. Using IP addresses OnlyAdded the 'skip-name-resolve' option to the /etc/mysql/my.cnf so it will not resolve ip address to names. This was an issue because the machine the connection is comming from is a web server, to it will have A*LOT of names. http://dev.mysql.com/doc/refman/5.0/en/dns.html http://lists.mysql.com/mysql/180963 Loging of user/connectivityTurned on logging to /var/log/mysql.log in the /etc/mysql/my.cnf http://www.washington.edu/computing/web/publishing/mysql-admin.html#logs http://dev.mysql.com/doc/refman/5.0/en/option-files.html User ManagmentSetting the administrator passwordSet the admin password from the root account command line, in linux of course. (replace "my_password", with the password) mysql -u root -e "set password = password('my_password');"
Creating a User by altering the mysql.user table
( Used to create user in CiviSpace mysql db) INSERT INTO user
+-----------------------+-----------------------------------+------+-----+---------+-------+ mysql> INSERT INTO user -> VALUES('%','monty',PASSWORD('some_pass'), -> 'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y'); mysql> INSERT INTO user SET Host='localhost',User='admin', -> Reload_priv='Y', Process_priv='Y'; mysql> INSERT INTO user (Host,User,Password) -> VALUES('localhost','dummy',);mysql> FLUSH PRIVILEGES; UPDATE user SET password=PASSWORD('something') WHERE user = 'monty'; could of used the grant privliages mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost' -> IDENTIFIED BY 'some_pass' WITH GRANT OPTION; mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'%' -> IDENTIFIED BY 'some_pass' WITH GRANT OPTION; mysql> GRANT RELOAD,PROCESS ON *.* TO 'admin'@'localhost'; mysql> GRANT USAGE ON *.* TO 'dummy'@'localhost'; Can use grant command to create user. GRANT ALL PRIBILEGES ON phpbbdb.* TO 'phpbb'@'localhost' IDENTIFIED BY 'Wha7Scrt4'; MySQL 4.1 How to create a user link http://dev.mysql.com/doc/refman/4.1/en/adding-users.html An example user add. (adding users who can just see values). mysql> insert into user (Host,User,Password) VALUES ( '10.16.10.136', 'metro', 'password '); *NOTE* with version 5.0 use to the PASSWORD() function when adding a password to a user. To find this out I only saw an error when the database server started, and it put a message in the log. *NOTE* with version 5.0 I also had to use the GRANT command to allow access to the databse. (? Not sure if you must also do this in 4 ? ) Make sure the privileges take effect. flush PRIVILEGES; Creating a userUser the create user command to create the user, then alter the privileges. create user fredsql; update mysql.user set select_priv='Y', insert_priv='y', update_priv='y',delete_priv='y',create_priv='y',alter_priv='y' where user = 'fredsql'; You may also want to set the users password now, use mysql; If you have granted all privilages you may want to take these away from a user. revoke CREATE USER, PROCESS, SHUTDOWN, SUPER, GRANT OPTION on *.* from 'fredsql'@'localhost'; Make sure the privileges take effect. flush PRIVILEGES; Admin password RecoveryOk, there is no real recovery, you can just reset the password. Stop the server sudo /etc/init.d/mysql stop Then start the server by hand, with the option to ingnore the server security sudo mysqld_safe --skip-grant-tables & Then login to the mysql server without a password mysql -u root Then reset the password via sql root@testtest:~# mysql -u root Then stop the server sudo /etc/init.d/mysql stop Then you should be done, netxt time you restart your server the password has been reset to what you want. Linkshttp://webyog.com/faq/23_36_en.html http://dev.mysql.com/doc/refman/5.0/en/connection-access.html http://dev.mysql.com/doc/refman/5.0/en/grant.html http://dev.mysql.com/doc/refman/5.0/en/adding-users.html http://www.cyberciti.biz/tips/recover-mysql-root-password.html Good link about mysql system tables for privlages and users http://www.idevelopment.info/data/MySQL/DBA_tips/Security/SEC_1.shtml Mysql Grant Syntax http://dev.mysql.com/doc/refman/5.0/en/grant.html Useful CommandsTo see all databases use mysql; select * from db; select Db from db; or show databases To Show tables show tables; To See info about the table describe {tablename}; To use a database use calld Database Backup/RecoveryThis is kind of primative, but works mysqldump -u root -p mysqldb > afile.text /usr/local/mysql/bin/mysqldump -u root -p --add-locks --extended-insert --all-databases > database_dump and try adding "--add-drop-database", only work on mysql db version 4.1.31 http://www.linuxcommand.org/man_pages/mysqldump1.html To recover from this file, I needed to delete the first part of the file, it is info about the mysql initernal database. Then I was able to load the rest of the file and thus all databases. For example, here is the begining of the dump file. You would need to start delete at the "CREATE DATABASE /*!32312 IF NOT EXISTS*/ mysql;" (including this line) line. -- MySQL dump 9.11 Delete up to the next, but not including the next "CREATE DATABASE" statement.
Then save the file, and you should be able to use the following statement to load the database in. mysql < the_data_base_dump_file.mysql
Here is a VI Macro to create a drop line out of a CREATE line in a dump file, then go and do another find (ie so you have to of already done a find on CREATE for it to find another one). Macro yyP$r;0dwiDROP \ESCn Note: Replace \ESC with an escape character, you can do this by entering insert mode and then doing Ctrl-V Esc example CREATE TABLE ac_table ( would be changed to DROP TABLE ac_table; This helped me reload a database, without having to drop the whole database. Exporting DataYou can export select fields out of the database. You can use the select command to export a select part of a database table. Here is an example that will export the database in a CSV format. SELECT *
By default mysql will export fields in a tab delmimted format. SELECT * INTO OUTFILE '/tmp/result.text';
Linkshttp://dev.mysql.com/doc/refman/5.0/en/load-data.html http://forums.mysql.com/read.php?79,150417,150742#msg-150742 http://forums.mysql.com/read.php?79,11324,13062#msg-13062 Other MySQL Database Info LinksLooks like a good general using mysql page. http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch34_:_Basic_MySQL_Configuration |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |