Mysql5.5的二进制安装

来源:互联网 发布:mac导入图片到iphone 编辑:程序博客网 时间:2024/05/21 10:41


下载mysql-5.5.32-linux2.6-x86_64.tar.gz 

安装包的解压

# tar xf mysql-5.5.32-linux2.6-x86_64.tar.gz 

# mv mysql-5.5.32-linux2.6-x86_64 /usr/local/mysql

# cd /usr/local/mysql

创建mysql用户和组

# groupadd -r mysql

# useradd -g mysql -r -s /sbin/nologin -M -d /usr/local/mysql/data mysql

创建数据库存放位置

# mkdir -pv /usr/local/mysql/data

# chown -R mysql.mysql /usr/local/mysql/data

初始化Mysql数据库

# cd /usr/local/mysql

# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

Installing MySQL system tables...
OK
Filling help tables...
OK


To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system


PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:


/usr/local/mysql//bin/mysqladmin -u root password 'new-password'
/usr/local/mysql//bin/mysqladmin -u root -h nginx1 password 'new-password'


Alternatively you can run:
/usr/local/mysql//bin/mysql_secure_installation


which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.


See the manual for more instructions.


You can start the MySQL daemon with:
cd /usr/local/mysql/ ; /usr/local/mysql//bin/mysqld_safe &


You can test the MySQL daemon with mysql-test-run.pl
cd /usr/local/mysql//mysql-test ; perl mysql-test-run.pl


Please report any problems with the /usr/local/mysql//scripts/mysqlbug script!


上面的2个OK说明Mysql已经初始化完成

查看到/usr/local/mysql/data/已生成文件 

  
#  ls /usr/local/mysql/data/     
ibdata1      ib_logfile1  mysql-bin.000001  mysql-bin.index  nginx1.pid          test
ib_logfile0  mysql        mysql-bin.000002  nginx1.err       performance_schema

#chown -R root  .

为mysql提供sysv服务脚本:


# cd /usr/local/mysql
# cp support-files/mysql.server  /etc/rc.d/init.d/mysqld


#vim /etc/init.d/mysqld

# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.


basedir=/usr/local/mysql            ####MYSQL程序包的安装位置
datadir=/usr/local/mysql/data    ####数据库的位置
根据内存大小复制Mysql配置文件
#cp /usr/local/mysql/support-files/my-huge.cnf /etc/my.cnf

#vim /etc/my.cnf

port            = 3306
socket          = /tmp/mysql.sock

# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 2   ####CPU数乘以2
datadir = /mydata/data      ####数据库的位置


# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id       = 1                ####server-id 默认是1 当要设置MySQL主从时,从服务器要修改为其他参数


/etc/my.cnf来自以下文件:

如果你的内存≤64M,则复制usr/local/mysql/support-files/my-small.cnf为/etc/my.cnf
# This is for a system with little memory (<= 64M) where MySQL is only used
# from time to time and it's important that the mysqld daemon
# doesn't use much resources.

如果内存是128M,则复制usr/local/mysql/support-files/my-medium.cnf为/etc/my.cnf
# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)

如果内存是512M,则复制usr/local/mysql/support-files/my-large.cnf为/etc/my.cnf
# This is for a large system with memory = 512M where the system runs mainly
# MySQL.

如果内存是1-2G,则复制usr/local/mysql/support-files/my-huge.cnf为/etc/my.cnf
# This is for a large system with memory of 1G-2G where the system runs mainly
# MySQL.
启动Mysql

# /etc/init.d/mysqld start

Starting MySQL..... SUCCESS! 

添加至服务列表:
# chkconfig --add mysqld
# chkconfig mysqld on

输出mysql的man手册至man命令的查找路径:


编辑/etc/man_db.conf,添加如下行即可:
MANDATORY_MANPATH                       /usr/local/mysql/man

输出mysql的头文件至系统头文件路径/usr/include:
这可以通过简单的创建链接实现:
# ln -sv /usr/local/mysql/include  /usr/include/mysql

输出mysql的库文件给系统库查找路径:


# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf

而后让系统重新载入系统库:
# ldconfig


修改PATH环境变量,让系统可以直接使用mysql的相关命令

/etc/porfile文件的最后加一段

# vim /etc/profile

declare -x PATH="/usr/local/mysql/bin:$PATH"

# source /etc/profile

#  mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.5.32-log MySQL Community Server (GPL)


Copyright (c) 2000, 2013, 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> 


设置Mysql密码

/usr/local/mysql//bin/mysqladmin -u root password 'YourPassword'


大功告成!!!

0 0
原创粉丝点击