您的位置:首页 > 数据库 > MySQL

Install and configure MySQL 5 with MacPorts

2013-05-18 22:19 459 查看

Install MySQL 5

You can install using Porticus, Port Authority, or from the command line:

?
The +server variant is required if you'll need to create a system startup item for MySQL 5. You'll see plenty of output during the build process and an activation message just before the installation completes.

Create initial MySQL databases

MySQL databases are kept in /opt/local/var/db/mysql5/ and you'll notice that this directory is empty. Run mysql_install_db to create the mysql and test databases.

?
You should see output similar to the following:

?

Options for starting MySQL

I personally don't want MySQL to start at system start up, I'll start it manually when I need it. If you're energy conscious and set your Mac to go to sleep you won't want to set mysqld to start at system boot either. If, however, you need MySQL to always
start at system boot

?
Whether you install the startup item or not, it's handy to add aliases to your profile to start and stop mysql from the command line. Use your favorite text editor (vi, pico, emacs) to add aliases.

?
or

?
Add the following:

?
?
Note: Notice the '5' at the end of mysqld_safe? MacPorts adds version numbers at the end of executables to allow the installation of multiple versions (i.e. MySQL 4 and 5). You'll need to add the version number at the end of some of the executables you use,
like mysqladmin5. Now you're ready to start your MySQL server with:

?
or, if you didn't create aliases

?

Confirm that MySQL is running

If MySQL's okay, you should see a server start confirmation message. You can test to ensure that MySQL is running with (leave password empty when prompted):

?
or with

?
If you get the following error...

?
...set the mysqld_safe socket path in a new MySQL configuration file. Create /opt/local/etc/mysql5/my.cnf, add the following to it, save, the try again.

?
NOTE: If you've installed MacPort's PHP 5 you will probably need to tell PHP where the MySQL socket is. Edit your php.ini file located at /opt/local/etc/php.ini.

?

Set Basic MySQL Security

Finally, set the root mysql password to secure your server.

?

Moving MySQL data from other installations

If, like me, you want to move data from a previous MySQL 5 install (i.e. /usr/local/mysql/data), be sure to stop MySQL first. You'll want to overwrite the mysql database you created after installation when copying over data files and indices. Ensure that
everything copied to /opt/local/var/db/mysql5/ remains owned by mysql. Refer to the MySQL documentation if you're upgrading from MySQL 4 to 5.

Now get busy querying.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: