MySQL的编译安装、部署与配置

MySQL是最流行的开源数据库,而PostgreSQL是最先进的开源数据库。虽然我现在自己已经全面投入PostgreSQL的怀抱中了,但是还有许多迷途的羔羊执迷不悟,或者无力抽身,不求上进,满足于MySQL。所以目前来看还有是有MySQL的使用需求的。本文描述了*nix下MySQL的源码安装方法。

从源码编译安装MySQL


  1. tar -zxvf mysql-5.7.9-osx10.10-x86_64.tar.gz
  2. mv mysql-5.7.9-osx10.10-x86_64 /usr/local/mysql
  3. chown -R root:wheel mysql
  4. bin/mysqld --initialize --user=mysql
  5. cd /usr/local
  6. sudo chown -R root:wheel mysql
  7. cd /usr/local/mysql
  8. sudo bin/mysqld --initialize --user=mysql
  9. # Remember the root password
  10. cp support-files/my-default.cnf /etc/my.cnf
  11. # Add Following content to /etc/my.cnf
  12. [client]
  13. default-character-set=utf8
  14. [mysqld]
  15. default-storage-engine=INNODB
  16. character-set-server=utf8
  17. collation-server=utf8_general_ci
  18. # Admin
  19. support-files/mysql.server start
  20. support-files/mysql.server restart
  21. support-files/mysql.server stop
  22. support-files/mysql.server status
  23. # Change Root Password
  24. bin/mysqladmin -u root -p password <newpassword>
  25. $ <Input temp password here>
  26. # login with root
  27. bin/mysql -p
  28. # Create Main User
  29. CREATE USER 'vonng'@'%' IDENTIFIED BY 'xxxx';
  30. grant all privileges on *.* to 'vonng'@'%' with grant option;
  31. create database vonng;
  32. create database test;
  33. # Create server user
  34. CREATE USER 'vonngserver'@'localhost' IDENTIFIED BY 'xxxx';
  35. grant all privileges on vonng.* to 'vonngserver'@'localhost';
  36. grant all privileges on test.* to 'vonngserver'@'localhost';
  37. flush privileges;
  38. # Uninstall
  39. sudo rm -rf /usr/local/mysql
  40. sudo rm -rf /usr/local/mysql*
  41. sudo rm -rf /Library/StartupItems/MySQLCOM
  42. sudo rm -rf /Library/PreferencePanes/My*
  43. sudo rm -rf /Library/Receipts/mysql*
  44. sudo rm -rf /Library/Receipts/MySQL*
  45. sudo rm -rf /var/db/receipts/com.mysql.*
  46. # Dump:
  47. /path/to/mysql/bin/mysqldump -u<username> -p <databasename> > dumpfile_name
  48. # Example: /usr/local/mysql/bin/mysqldump -uvonng -p cnzzdb > ~/Data/mysql/cnzzdb.sql
  49. # Recover
  50. mysql -u<username> -p -D <dbname> < dump_file_name
  51. # Example mysql -p -D testdb< ~/Data/mysql/cnzzdb.sql

在Mac上设置开机自动启动


  1. sudo vi /Library/LaunchDaemons/com.mysql.mysql.plist
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  4. <plist version="1.0">
  5. <dict>
  6. <key>KeepAlive</key>
  7. <true/>
  8. <key>Label</key>
  9. <string>com.mysql.mysqld</string>
  10. <key>ProgramArguments</key>
  11. <array>
  12. <string>/usr/local/mysql/bin/mysqld_safe</string>
  13. <string>--user=root</string>
  14. </array>
  15. </dict>
  16. </plist>
  17. sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysql.plist
上一篇:为Tornado配置Nginx反向代理


下一篇:windows server 2008解决盘符C盘变D盘的安装方法