记得上学的时候,“研究”过一次mysql,找了篇文章,在课堂上念了。至今已经10余年,居然没再碰过数据库,自以为做嵌入式不用数据库,回头一看,却已经out许久...
上网下到最新的mysql5.5,从头开始,以下全是按照官方指南执行的简化。
1、准备:
没cmake的装cmake,没make的装make,没perl的装perl,没gcc的...!
2、编译:
cd $MYSQL_SRC_DIR
cmake .(这儿有个点儿)
make install (多核的别忘了-j n,真的很快)
默认安装到/usr/local/mysql
cd /usr/local/mysql
3、配置:
我配置时是用的root用户,开发么,没管那么多。
scripts/mysql_install_db --user=mysql (root用户必须加上user选项)
脚本会在当前目录下建立data目录:
chown -R mysql data (修改一下所有者为mysql)
4、执行:
bin/mysqld_safe --user=mysql &
有问题如下:
[plain] view plaincopy
- 120630 22:50:11 mysqld_safe Logging to ‘/var/log/mysqld.log‘.
- 120630 22:50:11 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
- 120630 22:50:12 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
看一下/var/log/mysqld.log
[html] view plaincopy
- 120630 23:07:15 [ERROR] /usr/local/mysql/bin/mysqld: Can‘t create/write to file ‘/var/run/mysqld/mysqld.pid‘ (Errcode: 2)
- 120630 23:07:15 [ERROR] Can‘t start server: can‘t create PID file: No such file or directory
没那个目录,自己建一个,再加上权限,重新执行,提示:
[plain] view plaincopy
- 120630 23:18:53 mysqld_safe Logging to ‘/var/log/mysqld.log‘.
- 120630 23:18:53 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
应该是成功了。
5、测试:
bin/mysqladmin version,提示错误:
[plain] view plaincopy
- /usr/local/mysql/bin/mysqladmin: connect to server at ‘localhost‘ failed
- error: ‘Can‘t connect to local MySQL server through socket ‘/tmp/mysql.sock‘ (2)‘
- Check that mysqld is running and that the socket: ‘/tmp/mysql.sock‘ exists!
找mysql.sock这货没找到,看一下/etc/my.cnf (这是mysqld自己创建的,不愿意用可以到support-files下自己再找一个,反正都不是自己写的,以后再研究吧):
[plain] view plaincopy
- socket=/var/lib/mysql/mysql.sock
socket建立在/var下,那就ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock,什么都不用改了
再执行bin/mysqladmin version,提示:
[plain] view plaincopy
- /usr/local/mysql/bin/mysqladmin Ver 8.42 Distrib 5.5.24, for Linux on i686
- Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
- Oracle is a registered trademark of Oracle Corporation and/or its
- affiliates. Other names may be trademarks of their respective
- owners.
- Server version 5.5.24
- Protocol version 10
- Connection Localhost via UNIX socket
- UNIX socket /tmp/mysql.sock
- Uptime: 37 min 53 sec
- Threads: 1 Questions: 20 Slow queries: 0 Opens: 33 Flush tables: 1 Open tables: 26 Queries per second avg: 0.008
OK,其它的测试照着文档一点点的测就好了。
开发么,那么认真干嘛...