DesignLab
Thinker's Sofa
前言
这篇博文是以前写的,有些地方不是很专业,大家凑合看吧,当然按照步骤成功安装MYSQL是不成问题的。
安装环境说明:
系统:ubuntu 11.10
MySql:mysql 5.5.17
1,在Root下尝试
主要由于我在普通用户下的权限问题搞的有点头大,所以切了过来。
1.1 MYSQL安装
在这里先列一下安装说明里面的解答:
- To install and use a MySQL binary distribution, the basic command
- sequence looks like this:
- shell> groupadd mysql
- shell> useradd -r -g mysql mysql
- shell> cd /usr/local
- shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
- shell> ln -s full-path-to-mysql-VERSION-OS mysql
- shell> cd mysql
- shell> chown -R mysql .
- shell> chgrp -R mysql .
- shell> scripts/msql_install_db --user=mysql
- shell> chown -R root .
- shell> chown -R mysql data
- # Next command is optional
- shell> cp support-files/my-medium.cnf /etc/my.cnf
- shell> bin/mysqld_safe --user=mysql &
- # Next command is optional
- shell> cp support-files/mysql.server /etc/init.d/mysql.server
提示:ubuntu默认root不设密码,所以你无法登录,在当前用户下,终端输入:sudo passwd root 输入当前用户登录密码,再设置root用户密码就可以了
附命令记录:
- cd /etc
- rm my.cnf
- rm -rf mysql/
- cd /
- find -name "mysql" -print
- cd /etc/apparmor.d/abstractions/
- rm -rf mysql
- groupadd mysql
- useradd -r -g mysql mysql
- cd /usr/local
- cd src
- ln -s /usr/local/src/mysql-5.5.17-linux2.6-i686/ mysql
- cd mysql
- chown -R mysql .
- chgrp -R mysql .
- scripts/mysql_install_db --user=mysql
- chown -R root .
- chgrp -R mysql .
- chown -R root .
- chown -R mysql data
- ls -l
- bin/mysqld_safe --user=mysql &
前面可能因为没有chown -R mysql data产生了一系列问题,不知道是不是根本原因所在,先记录一下。执行到这地方,命令行会返回一个进程号,终端提示mysql进程启动,一定没有报错才行。这证明mysql启动了。
1.2 测试服务
新开一个终端,进行如下操作:
- /usr/local/mysql/bin/mysqladmin version
root@air:~# /usr/local/mysql/bin/mysqladmin version
/usr/local/mysql/bin/mysqladmin Ver 8.42 Distrib 5.5.17, for linux2.6 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.17
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /tmp/mysql.sock
Uptime: 1 min 5 sec
Threads: 1 Questions: 1 Slow queries: 0 Opens: 33 Flush tables: 1 Open tables: 26 Queries per second avg: 0.015
1.3配置参数
接下来,我们把默认的配置文件复制到/etc文件夹下,命名为my.cnf文件,命令如下:
- cd /usr/local/mysql
- cp support-files/my-medium.cnf /etc/my.cnf
现在我们做好了启动服务的准备工作,可以启动了:
- bin/mysql -u root -p
root@air:/usr/local/mysql# bin/mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.17 MySQL Community Server (GPL)
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.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
# 输\s看下状态,\q退出。
1.4安全配置
现在我们服务起来了,但是密码等都没有设置,接下来我们可以运行如下命令:
- root@air:/usr/local/mysql# bin/mysql_secure_installation
- NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
- SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
- In order to log into MySQL to secure it, we'll need the current
- password for the root user. If you've just installed MySQL, and
- you haven't set the root password yet, the password will be blank,
- so you should just press enter here.
- Enter current password for root (enter for none):
- ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
- Enter current password for root (enter for none):
- ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
- Enter current password for root (enter for none):
- OK, successfully used password, moving on...
- Setting the root password ensures that nobody can log into the MySQL
- root user without the proper authorisation.
- Set root password? [Y/n] y
- New password:
- Re-enter new password:
- Password updated successfully!
- Reloading privilege tables..
- ... Success!
- By default, a MySQL installation has an anonymous user, allowing anyone
- to log into MySQL without having to have a user account created for
- them. This is intended only for testing, and to make the installation
- go a bit smoother. You should remove them before moving into a
- production environment.
- Remove anonymous users? [Y/n] y
- ... Success!
- Normally, root should only be allowed to connect from 'localhost'. This
- ensures that someone cannot guess at the root password from the network.
- Disallow root login remotely? [Y/n] y
- ... Success!
- By default, MySQL comes with a database named 'test' that anyone ca
- access. This is also intended only for testing, and should be removed
- before moving into a production environment.
- Remove test database and access to it? [Y/n] y
- - Dropping test database...
- ERROR 1010 (HY000) at line 1: Error dropping database (can't rmdir './test/', errno: 17)
- ... Failed! Not critical, keep moving...
- - Removing privileges on test database...
- ... Success!
- Reloading the privilege tables will ensure that all changes made so far
- will take effect immediately.
- Reload privilege tables now? [Y/n] y
- ... Success!
- Cleaning up...
- All done! If you've completed all of the above steps, your MySQL
- installation should now be secure.
- Thanks for using MySQL!
2.环境变量以及自启动
2.1 配置环境变量
但是我们发现每次运行命令基本上都要输入绝对路径,或者在安装目录下运行bin/###.##等,如果用apt-get安装的话是不会遇到这个问题的,主要是安装程序已经帮你做了。这里面我们设置环境变量来解决这个问题,类似Windows下配置JDK环境,需要设置JAVA命令PATH一样,在Ubuntu下,环境变量可以设置成用户级或者系统级,区别是对单个用户还是对全局用户都生效,是对BASH生效还是其他等等,这个我也刚接触,列举下面的操作流程和方法,我采用系统级变量:
系统环境变量一般保存在下面的文件中:
/etc/environment
/etc/profile
/etc/bash.bashrc
/etc/profile和 /etc/bash.bashrc在Ubuntu 10.0版本中不推荐使用。
如想将一个路径加入到$PATH中,可以像下面这样做(修改/etc/profile):
- $ sudo nano /etc/profile
添加如下语句:
- export PATH="$PATH:/my_new_path"
- $source /etc/profile
需要注意的是,最好不要把当前路径”./”放到PATH里,这样可能会受到意想不到的攻击。
其他文件的修改方式与此类似,需要注意的是/etc/environment不需要使用export设置环境变量,其他profile文件需要。
这样所有用户下的终端都认识/usr/local/mysql/bin下的命令了。
2.2 配置自启动
可以如下启动:
- /usr/local/mysql/bin/mysqld //启动Mysql服务
- /usr/local/mysql/bin/mysql -u root //访问Mysql服务器
- /usr/local/mysql/bin/mysqladmin -u root -p shutdown //关闭mysql服务器
- /usr/local/mysql/bin/mysqld &
- cp /usr/local/mysql/support-files/my.server /etc/init.d/mysqld
- sudo update-rc.d mysqld default
当然以后启动可以直接输入
- /etc/init.d/mysqld restart|start
几个常见错误:
常见错误1:第一次在普通用户权限下安装,可能因为权限的问题,并丢失了一个操作步骤,所以导致安装成功,但是每次启动总报错:
- air@air:/usr/local/mysql/bin$ sudo /usr/local/mysql/bin/mysqld_safe --user=mysql &
- [1] 6378
- air@air:/usr/local/mysql/bin$ 111116 11:58:56 mysqld_safe Logging to '/var/log/mysql/error.log'.
- touch: 无法创建"/var/log/mysql/error.log": 没有那个文件或目录
- chown: 无法访问"/var/log/mysql/error.log": 没有那个文件或目录
- 111116 11:58:56 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
- /usr/local/mysql/bin/mysqld_safe: 107: /usr/local/mysql/bin/mysqld_safe: cannot create /var/log/mysql/error.log: Directory nonexistent
- /usr/local/mysql/bin/mysqld_safe: 1: eval: cannot create /var/log/mysql/error.log: Directory nonexistent
- 111116 11:58:57 mysqld_safe mysqld from pid file /var/lib/mysql/air.pid ended
希望有大牛能够指点一下,不是很明白。
常见错误2:
- air@air:/usr/local/mysql$ scripts/mysql_install_db --user=mysql
- FATAL ERROR: Could not find mysqld
- The following directories were searched:
- /usr/libexec
- /usr/sbin
- /usr/bin
- If you compiled from source, you need to run 'make install' to copy the software into the correct location ready for operation.
- If you are using a binary release, you must either be at the top level of the extracted archive, or pass the --basedir option pointing to that locatio
- 命令:ln -s /usr/local/src/mysql-VERSION mysql
- 解压:sudo tar zxvf /path/to/your/source.tar.gz
常见问题3:
- air@air:/usr/local/mysql$ sudo scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql
- Installing MySQL system tables...
- /usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
- Installation of system tables failed! Examine the logs in
- /var/lib/mysql for more information.
- You can try to start the mysqld daemon with:
- shell> /usr/local/mysql/bin/mysqld --skip-grant & and use the command line tool /usr/local/mysql/bin/mysql to connect to the mysql database and look at the grant tables:
- shell> /usr/local/mysql/bin/mysql -u root mysql
- mysql> show tables
- Try 'mysqld --help' if you have problems with paths. Using --log gives you a log in /var/lib/mysql that may be helpful.
- Please consult the MySQL manual section 'Problems running mysql_install_db', and the manual section that describes problems on your OS. Another information source are the MySQL email archives available at http://lists.mysql.com/.
- Please check all of the above before mailing us! And remember, if you do mail us, you MUST use the /usr/local/mysql/scripts/mysqlbug script!
主要是少了libaio.so.1这个文件,网上搜一下,或者新立得或者软件中心搜一下,
知道要安装如下包:
libaio1 0.3.109-2ubuntu1,
安装以下不再报错。
任何问题,欢迎斧正
-
博文推荐
- android MediaScanner...
- Hibernate
- 数据库语言分类
- ubuntu 中找不到libgtk-x1...
- sql时间查询
- Oracle导入导出数据库
- Ubuntu 14.04上安装WineT...
- SharePoint部署WSP解决方案包...
核心技术类目
- 个人资料
-
- 访问:64005次
- 积分:1190分
- 排名:第11596名
- 原创:52篇
- 转载:12篇
- 译文:0篇
- 评论:43条
- 博客专栏
Linux系统简明教程 文章:8篇
阅读:4529
- 文章分类
- 服务器调试及管理(20)
- 编程技术与思想(6)
- LINUX_STEP_BY_STEP文档(11)
- WEB DESIGN(7)
- SHELL_SCRIPT(10)
- C/C++(4)
- Linux(9)
- 阅读排行
- 解决tomcat报错 java.net.ConnectException: Connection refused问题的方法(9313)
- HowTo:Ubuntu11.10 安装Oracle10g备忘录(3155)
- Ubuntu上配置SVN,Apache服务以及常见问题解决方法(3151)
- svn update报no such revision * 的解决方法(2452)
- 关于Tomcat服务器出现error occurred during initialization of vm ,noclassdeffounderror错误的问题(2402)
- svn中import 从本地编码转换到UTF8失败以及checkout到本地后svn 工作副本已经锁定,尚未纳入版本控制解决(2200)
- Linux排版利器-TeX可视化工具LyX中文编辑环境安装配置指南(2152)
- HOWTO:Mantis Bug Tracker Step-by-Step安装说明(1897)
- Ubuntu,Mysql二进制安装流程以及常见错误(1644)
- 人类已经无法阻止理工科宅男了~~~(Gnuplot 和 Matplotlib使用小节)(1616)
- 评论排行
- HowTo:Ubuntu11.10 安装Oracle10g备忘录(9)
- 计算机本科开设课程示意图---解答目前大学开设这些课程的原因(9)
- LINUX系统学习系列---备忘录(7)
- python学习备忘录--1(2)
- JS倒计时、跳转模块以及JSP中比较日期跳转模块(2)
- 心情随笔3(2)
- OpenAFS服务器重新安装流程(2)
- svn中import 从本地编码转换到UTF8失败以及checkout到本地后svn 工作副本已经锁定,尚未纳入版本控制解决(2)
- 解决tomcat报错 java.net.ConnectException: Connection refused问题的方法(2)
- Jquery学习备忘录(1)
- 最新评论
- HowTo:Ubuntu11.10 安装Oracle10g备忘录
altand:@tombwen:可以给个邮箱撒?
- HowTo:Ubuntu11.10 安装Oracle10g备忘录
altand:@tombwen:好久前的写的,都已经忘了,不过高手就是高手,有空指点指点啊,哈哈,
- HowTo:Ubuntu11.10 安装Oracle10g备忘录
tombwen:关于3.4,在那个错误执行的脚本中,在gcc的引用的东西中国添加LOCALNETLIBS中的like...
- HowTo:Ubuntu11.10 安装Oracle10g备忘录
altand:@tombwen:果然还是有高手的,这个当时弄了很长时间,翻了不少资料,还是没有完美解决,多谢啊
- HowTo:Ubuntu11.10 安装Oracle10g备忘录
tombwen:关于3.3,是因为库的引用顺序有问题,按如下修改就ok了LSNRCTL_LINKLINE=$(LIN...
- 解决tomcat报错 java.net.ConnectException: Connection refused问题的方法
justgou:学习
- 解决tomcat报错 java.net.ConnectException: Connection refused问题的方法
varyli:恩,不错!
- svn中import 从本地编码转换到UTF8失败以及checkout到本地后svn 工作副本已经锁定,尚未纳入版本控制解决
yudca:果然删除了log文件,问题解决了,谢谢楼主
- LINUX系统学习系列---备忘录
张德裕:赞~~~~
- LINUX系统笔记2---系统的引导
平原上的星星:作者写的很用心,佩服!
- 推荐文章