Installing MySQL from a tarball

来源:互联网 发布:php 权限拦截器 编辑:程序博客网 时间:2024/04/30 07:48

Installing MySQL from a tarball

Installing MySQL from a tarball should be straightforward but there are several steps, and therefore several opportunities for things to get funky. Nonetheless, doing it this way you will learn more about several aspects of your system, and what's really going on with the installation, and you'll see all the work that you'd save by using rpm.

Installing things from tarballs is a common practice on UNIX/Linux systems. You'll be doing it later when you install DBI as well. By then you'll be a pro. It usually involves just a few simple steps. Tarballs usually come as compressed, tar'd files. tar stands for Tape Archive, and refers to a format for storing and archiving files and directory structures. When you unpack a tar ball it recreates the original directory structure and files.

The binary source tarball comes with everything you need to run MySQL, as well as all the client programs for interacting with the database, and the development libraries for writing or using your own programs with the database. To install the software you should be able to log into your system as root. By default, mysql would run as a root process, and some of the files would be owned by root. Because this is something of a security risk, many people choose to create a regular user for running the mysql deamon. This way there are less root owned files on your system, and fewer opportunities for exploiting a root owned process. Once you have the software, and created a user, you can install the database and start it up. The last steps are simply to set an administration password, and then modify your system so that it starts the mysql deamon everytime the system is started.

Installation Overview

Basically you'll be performing the following steps:
  1. Get the tarball
  2. decompress and unpack the tarball
  3. create a symbolic link to the mysql directory
  4. create a user whose ID is used for running the database
  5. change ownership of the directory from root to user mysql
  6. edit the init startup file
  7. su to user mysql
  8. initialize the database and create the tables with the included install script
  9. start the database
  10. change the root password
  11. change back to user root
  12. place startup file in proper startup location

Get the software and unpack it

The tarball is more formally called a binary source distribution. You can get the source distribution at the same place you get the rpm files: www.mysql.com. It will have some filename like: mysql-3.22.32-pc-linux-gnu-i686.tar.gz

A common place to install software on linux systems is in the directory:

/usr/local/

Once you have the software, log in as root and move the tarball to that directory. The filename of the software will have two extenions on the end: .tar.gz The gz indicates that the file is compressed. To uncompress the file issue the command:

gunzip filename.tar.gz

this will decompress the file and remove the .gz extension. Now you have a true tar file. Unpack it using the tar command with the appropriate arguments:

tar -xvf filename.tar

the x means extract, the v means verbose (show me everything that's happening), and the f indicates that the next argument is the filename to extract. You should see the names of files and directories wizzing by your screen. If you list the contents of the current directory you should see that a new directory containing all the mysql files has been created.

Now that you have the distribution unpacked, it's a good idea to create the user that will own the files and run the database. You can do this with the addusercommand.

Since it has a long clunky name, you should create a symbolic link to it (the same thing as an alias or shortcut):

Create a user for the mysql program

From a security point of view you'd like to run the server as some user other than root. It's also a good idea to not have any more root-owned files lying around your system than are necessary. To accomplish this you can simply create a user and group for owning and running the server. I create a user called mysql, with no home directory. We do this with the adduser and groupadd commands.
/usr/sbin/groupadd mysql#create the user mysql with no home directory and group mysql/usr/sbin/adduser mysql -M -g mysql
Now su to user mysql and initialize your database tables. It's important to do this as the user mysql, because otherwise the tables and directories will be created as owned by root
[root@zenith mysql]#su mysql[mysql@zenith mysql]#[mysql@zenith mysql]# scripts/mysql_install_db Creating db tableCreating host tableCreating user tableCreating func tableCreating tables_priv tableCreating columns_priv tableTo start mysqld at boot time you have to copy support-files/mysql.serverto the right place for your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !This is done with:./bin/mysqladmin -u root password 'new-password'See the manual for more instructions.Please report any problems with the ./bin/mysqlbug script!The latest information about MySQL is available on the web at http://www.mysql.comSupport MySQL by buying support/licenses at http://www.tcx.se/license.htmy.[mysql@zenith mysql-3.22.32-pc-linux-gnu-i686]#

Now before you can set the root password, you must start the mysqld daemon. This is done with a little script in the scripts directory called safe_mysqld.

[root@zenith mysql-3.22.32-pc-linux-gnu-i686]# bin/safe_mysqld &[1] 1541[root@zenith mysql-3.22.32-pc-linux-gnu-i686]# Starting mysqld daemon with databases from /usr/local/mysql-3.22.32-pc-linux-gnu-i686/data

You can see if the daemon is running by looking at all the system process:

ps aux | more

Now try setting the root password:

[root@zenith mysql-3.22.32-pc-linux-gnu-i686]# ./bin/mysqladmin -u root password 'friday'

You can also try connecting to the server and issuing a command:

[root@zenith mysql-3.22.32-pc-linux-gnu-i686]# bin/mysql -pfridaymysql> show databases;+----------+| Database |+----------+| mysql    || test     |+----------+2 rows in set (0.00 sec)mysql> 

Set the mysql daemon to start at system start up

Next we have to make it so that the mysql server will start up everytime the computer is started. This is accomplished by a script that holds information about how the server should be started. We need to edit that script and place it in the proper location for system start up. There's a place onthe system for start up files edit support-files/mysql.server and change user to mysql
[root@zenith support-files]# cp mysql.server mysql.server-dist[root@zenith support-files]# emacs -nw mysql.server[root@zenith support-files]# cp mysql.server /etc/rc.d/init.d/[root@zenith support-files]# cd /etc/rc.d/init.d/[root@zenith init.d]# chmod a+x mysql.server [root@zenith init.d]# ls -al mysql.server-rwxrwxr-x   1 root     root         2815 Oct  9  2000 mysql.server
When your system starts up there is a series of things in rc.d directory that occur. To add mysql as one of the things that gets started use the chkconfig command. Type: man chkconfig for more information on this. Or continuing from above, issue the following comands:
[root@zenith init.d]# /sbin/chkconfig --add mysql.server[root@zenith init.d]# /sbin/chkconfig --list mysql.servermysql.server 0:off 1:off 2:on 3:on 4:on 5:on 6:off[root@zenith init.d]#

The first command "chkconfig --add" adds the proper links in the right places for your system to execute the mysql.server script upon system startup. The second command "chkconfig --list" reports back to you the run levels in which the script is executed.

It's also a good idea to add the path to the mysql bin directory to the default path of users.

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 信无法寄到该怎么办 5个月的宝宝光有屎沫怎么办 胸牌的别针坏了怎么办 工资表税金扣多了怎么办? 装修公司不发放工程怎么办 公司不给开收入证明怎么办 装修公司不付工人工资怎么办 收入证明少500元怎么办 dnf二级输错了怎么办 如果受到法律的伤害怎么办 86岁了还怕死怎么办 风衣的腰带丢了怎么办 成为伪娘身上的毛怎么办 军官升不上去了怎么办 王者荣耀代练封号怎么办 cf淘宝代练封号怎么办 买音乐会的票过期怎么办 十年多年前被怨错拘留了怎么办 与室友关系闹僵怎么办 开庭后被告威胁我们证人怎么办 开车撞了豪车怎么办 我把人撞了全责怎么办 开车撞伤人没钱赔怎么办 开车撞伤无证驾驶人怎么办 开车把人撞伤了只买交强险怎么办 开车撞伤人赔不起怎么办 如果车撞死人了怎么办 给车撞了跑了怎么办 开车把人撞死了怎么办 开车把人蹭了怎么办 驾照被扣54分怎么办? 驾照被扣了12分怎么办 驾驶证丢失后被扣分怎么办 驾照扣了三十分怎么办 一次被扣了12分怎么办 驾照被扣35分后怎么办 我驾驶证扣了6分怎么办 c1驾照被扣6分怎么办 被扣了6分怎么办 今年扣了6分怎么办 驾照分不够扣了怎么办