`
sunchaohui_koko
  • 浏览: 57359 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

Install and Configure MySQL on Linux

    博客分类:
  • java
阅读更多

wget http://mirrors.sohu.com/mysql/MySQL-6.0/MySQL-server-6.0.10-0.glibc23.i386.rpm
wget http://mirrors.sohu.com/mysql/MySQL-6.0/MySQL-client-6.0.10-0.glibc23.i386.rpm
wget http://mirrors.sohu.com/apache/httpd-2.2.16.tar.gz

#卸载Mysql
rpm -qa|grep -i mysql
rpm -ev MySQL-server-4.0.14-0 MySQL-client-4.0.14-0
#彻底删除
rm -rf /var/lib/mysql
rm -f /etc/my.cnf

#安装
yum -y install gcc

groupadd mysql
useradd -g mysql mysql
[yum -y install gcc+ gcc-c++]
./configure --prefix=/opt/mysql --with-charset=utf8 --with-extra-charsets=all --with-tcp-port=3306 --with-unix-socket-path=/opt/mysql/var/mysql.sock --with-mysqld-user=mysql --with-federated-storage-engine --with-named-curses-libs=/usr/lib/libncurses.so.5 --without-plugin-falcon
make
make install

scripts/mysql_install_db

cp support-files/my-huge.cnf /opt/mysql/var/my.cnf

 

 

======================

MySQL 有年头了,写篇简单的文档来记录下自己的常用安装和配置过程。本文旨在介绍如何在 Linux 系统上安装 MySQL 数据库服务器,以及基本配置。本文仅仅提供一份快速指南,请访问 MySQL 官方网站获取详细安装、配置指南。

OS: Red Hat Enterprise Linux AS 3.0
MySQL: 5.0.22

源码 tarball 放置在 /home/huangys , 安装目的地是/opt/mysql

1. 准备

创建一个用户来运行 MySQL 守护进程。
# groupadd mysqlg
# useradd –g mysqlg –M –s /sbin/nologin mysqld

解包
# cd /home/huangys
# tar zxvf mysql-5.0.22.tar.gz

2. 配置编译选项

# cd mysql-5.0.22
# ./configure --prefix=/opt/mysql --with-charset=utf8 --with-extra-charsets=all --with-tcp-port=3306 --with-unix-socket-path=/tmp/mysql.sock --with-mysqld-user=mysqld --with-federated-storage-engine

选项说明:
--prefix=/opt/mysql 将MySQL安装到目录/opt/mysql
--with-charset=utf8 指定缺省字符集为utf8
--with-extra-charsets=all 将MySQL所有支持的字符集编译进来
--with-tcp-port=3306 指定此MySQL实例将监听TCP 3306端口
--with-unix-socket-path=/tmp/mysql.sock 指定UNIX socket文件的路径(为绝对路径)
--wih-mysqld-user=mysqld 指定用来运行MySQL守护进程的用户
--with-federated-storage-engine 支持federated存储引擎

--with-plugins=innobase  支持innobase数据库(5.1+,默认为空)

--without-debug \去除debug模式
--with-extra-charsets=gb2312 \添加gb2312中文字符支持
--enable-assembler \使用一些字符函数的汇编版本
--without-isam \去掉isam表类型支持 现在很少用了 isam表是一种依赖平台的表 (5.0以前)
--without-innodb \去掉innodb表支持 innodb是一种支持事务处理的表,适合企业级应用 5.0以前)

--with-pthread \强制使用pthread库(posix线程库)
--enable-thread-safe-client \以线程方式编译客户端
--with-client-ldflags=-all-static \
--with-mysqld-ldflags=-all-static \以纯静态方式编译服务端和客户端

通过指令 configure --help 可以查看全部选项信息。

 

----prefix  必须指定

--with-unix-socket-path 最好指定自己的路径

 

 优化编译:

1. -static  13%
   --with-client-ldflags=-all-static
   --with-mysqld-ldflags=-all-static
静态链接提高13%性能

2. -pgcc  1%
   CFLAGS="-O3 -mpentiumpro -mstack-align-double" CXX=gcc \
     CXXFLAGS="-O3 -mpentiumpro -mstack-align-double \
     -felide-constructors -fno-exceptions -fno-rtti"
如果是Inter处理器,使用pgcc提高1%性能

3. Unix Socket  7.5%
   --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock
使用unix套接字链接提高7.5%性能,所以在windows下mysql性能肯定不如unix下面

4. --enable-assembler
允许使用汇编模式(优化性能)
  

如:./configure --prefix=/opt/aimcpro10/mysql-5.1.45  --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --with-unix-socket-path=/opt/aimcpro10/mysql-5.1.45/mysql.sock
--enable-assembler --with-charset=utf8 --with-extra-charsets=gbk  --with-plugins=innobase,myisam


 

3. 编译、安装

# make
# make install

4. 初始化

# scripts/mysql_install_db
这将会在安装目录 /opt/mysql 下创建 MySQL 的数据目录 var

5. 配置

在 MySQL 提供的支持文件中复制一个合适的配置档到 MySQL 数据目录中,并命名为 my.cnf
# cp support-files/my-huge.cnf /opt/mysql/var/my.cnf

主要修改点在 [mysqld] 配置块中:

指定允许的最大包尺寸:
max_allowed_packet = 2M

指定最大连接数(默认为100):
max_connections = 1000

指定服务器端字符集:
character_set_server = utf8

强制指定连接使用的字符集:
init_connect = 'set names utf8'
(注意:若连接时使用的是 super user ,则此项不会被执行,MySQL 文档对此有详细解释。)

指定安装目录和数据目录:
basedir = /opt/mysql2/
datadir = /opt/mysql2/var/

忽略Berkeley DB:
skip-bdb
(同理,若也打算忽略 InnoDB,则使用 skip-innodb)

配置InnoDB:
innodb_data_home_dir = /opt/mysql2/var/
innodb_data_file_path = ibdata1:500M;ibdata2:50M:autoextend
innodb_log_group_home_dir = /opt/mysql2/var/
innodb_log_arch_dir = /opt/mysql2/var/
innodb_buffer_pool_size = 384M
innodb_additional_mem_pool_size = 20M
innodb_log_file_size = 100M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50

完成编辑此配置档后,记得顺便修改一下 MySQL 数据目录的 ownership:
# cd /opt/mysql
# chown –Rc mysqld.mysqlg var

6. 控制脚本

MySQL提供了一个脚本文件,可以用来方便地控制MySQL守护进程。
# cp support-files/mysql.server /opt/mysql/bin/mysqlctl
# cd /opt/mysql/bin
# chmod 755 mysqlctl

启动:
# /opt/mysql/bin/mysqlctl start
停止:
# /opt/mysql/bin/mysql stop

注意,若启用了 InnoDB 存储引擎,那么第一次启动 MySQL 服务器时,速度会比较慢,因为需要分配在配置档中定义的空间、生成相应的数据文件、日志文件等。

7. Security

安全问题在哪里都是很重要的,特别是对于初安装的新系统而言,尤其如此。

MySQL 往往携带有四个缺省用户,分别是 'root'@'localhost', 'root'@'%', ''@'localhost', ''@'%'.
除了第一个本地root,其他三个(任意来源的root,以及两个匿名用户)都应该删除:

mysql> use mysql
mysql> delete from user where user='';
mysql> delete from user where user='root' and host='%';

这唯一保留的用户 root@localhost 的密码默认为空,当然不好。为它加上密码:

# /opt/mysql/bin/mysqladmin -uroot -hlocalhost -P3306 -p password my_pass

指令中的 my_pass 就是设定的密码,注意,不要用单引号把它括起来。

8. Appendix

[root@tbox2 root]# cat /etc/redhat-release
Red Hat Enterprise Linux AS release 3 (Taroon)

[root@tbox2 root]# uname -a
Linux tbox2.test.net 2.4.21-4.ELsmp #1 SMP Fri Oct 3 17:52:56 EDT 2003 i686 i686 i386 GNU/Linux

[root@tbox2 root]# rpm -qa | grep gcc
libgcc-ssa-3.5ssa-0.20030801.41
gcc-g77-3.2.3-20
gcc-ssa-3.5ssa-0.20030801.41
gcc-objc-ssa-3.5ssa-0.20030801.41
compat-gcc-c++-7.3-2.96.122
compat-gcc-7.3-2.96.122
gcc-c++-3.2.3-20
gcc-gnat-3.2.3-20
gcc-objc-3.2.3-20
gcc-c++-ssa-3.5ssa-0.20030801.41
gcc-java-ssa-3.5ssa-0.20030801.41
libgcc-3.2.3-20
gcc-3.2.3-20
gcc-java-3.2.3-20
gcc-g77-ssa-3.5ssa-0.20030801.41

[root@tbox2 root]# rpm -qa | grep glibc
glibc-headers-2.3.2-95.3
glibc-common-2.3.2-95.3
glibc-utils-2.3.2-95.3
glibc-kernheaders-2.4-8.34
glibc-devel-2.3.2-95.3
compat-glibc-7.x-2.2.4.32.5
glibc-2.3.2-95.3
glibc-profile-2.3.2-95.3

[root@tbox2 root]# /opt/mysql/bin/mysql --version
/opt/mysql/bin/mysql  Ver 14.12 Distrib 5.0.22, for pc-linux-gnu (i686) using  EditLine wrapper

 

END.

 

--------------------------------------------------------------------------------------------------------------------

./configure --prefix=/home/jack/mysql/ --with-unix-socket-path=/home/jack/mysql/mysql.sock
make
make install
cp /usr/local/share/mysql/my-large.cnf   /home/jack/mysql/my.cnf
cd /home/jack/mysql
bin/mysql_install_db
bin/mysqld_safe &

 

**********************************************************************
**********************************************************************
**********************************************************************
 
手工安装mysql
 
 
1.改路径参数
mysqld_safe
mysqld_multi
mysqlaccess
mysql_upgrade_shell
mysql_install_db
mysqlbug
mysql_fix_privilege_tables
mysql_config  (还要改mysql.sock)
msql2mysql
mysql_fix_privilege_tables
mysql_install_db
mysqld_safe
把这些文件里的路径,例如 :"/export/nfs10/builder/aimc3rd/mysql5/" 改为实际的路径
使用命令:
:%s/\/export\/nfs10\/builder\/aimc3rd\/mysql5/\/opt\/aimm\/aimm\/mysql5
 
2.复制~/mysql5/share/mysql/my-medium.cnf ~/mysql5/.my.cnf
  然后修改参数
[client]
#password       = your_password
port            = 3336
socket          = /opt/aimm/aimm/mysql5/mysql.sock
default-character-set = utf8
 
3.初始化数据库,执行脚本mysql_install_db

4.启动数据库
./bin/mysqld_safe --defaults-file=./.my.cnf
5.连接数据库,新建用户aimm/aimm
/mysql -h127.0.0.1 -P3336 -uroot -p
grant all on *.* to aimm@"%" identified by "aimm"
 
---改密码:mysql> update user set Password=Password('aimc1234') where User='aiuum';
---mysql> FLUSH PRIVILEGES;
 
mysql> select * from user where user = '';
mysql> delete from user where user = '';
 
--------------------------------------------------------------
--------------------------------------------------------------
mysql编译参数详解
 

./configure \
--prefix=/usr/local/mysql \
--enable-assembler \
--without-debug \
--with-charset=utf8 \
--with-extra-charsets=all \
--with-pthread \
--enable-thread-safe-client \
--enable-local-infile \
--with-client-ldflags=-all-static \
--with-mysqld-ldflags=-all-static \
--with-big-tables \
--without-innod \
--without-isam 2;
--with-ssl \
--with-embedded-server \
 

--enable-assembler \使用一些字符函数的汇编版本
--without-debug \去除debug模式
--with-charset=utf8 \
--with-extra-charsets=complex字符支持
--with-pthread \强制使用pthread库(posix线程库)
--enable-thread-safe-client \以线程方式编译客户端
--with-client-ldflags=-all-static \以纯静态方式编译客户端
--with-mysqld-ldflags=-all-static \以纯静态方式编译服务端
--with-big-tables
There is a limit of 232 (~4.295E+09) rows in a MyISAM table. If you build MySQL with the --with-big-tables option, the row limitation is increased to (232)2 (1.844E+19) rows
--without-innodb \去掉innodb表支持,innodb是一种支持事务处理的表,适合企业级应用
--enable-local-infile #让mysql支持从本地文件 导入数据库
--without-isam \去掉isam表类型支持,现在很少用了,isam表是一种依赖平台的表
--with-embedded-server #编译成embedded MySQL library (libmysqld.a)

--------------------------------------

MySQL编译调整优化简明指南

http://blog.chinaunix.net/u1/36506/showart_432783.html

分享到:
评论

相关推荐

    24小时教会PHP, MySQL and Apache(英文)

    The book teaches the reader to install, configure and set up the PHP scripting language, the MySQL database system, and the Apache Web server. By the end of this book the reader will understand how ...

    MySQL 8 Cookbook epub 格式

    Install and configure your MySQL 8 instance without any hassle Get to grips with new features of MySQL 8 like CTE, Window functions and many more Perform backup tasks, recover data and set up various ...

    mysql-8-cookbook2018

    to install MySQL 8 on different flavors of Linux, upgrade to MySQL 8 from previous stable releases, and also downgrade from MySQL 8. Chapter 2, Using MySQL, takes you through the basic uses of MySQL, ...

    CentOS 7.0编译安装cmake和mysql安装包

    ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql #生成mysql系统数据库 ln -s /usr/local/mysql/my.cnf /etc/my.cnf #添加到/etc目录的软连接 cp ./support-files/...

    CentOS宝典.pdf

    First find out how to install and configure CentOS. From there, you'll cover a wealth of Linux and CentOS tools, functions, and techniques, including: how to work in the GNOME and KDE desktop ...

    Getting Started with MariaDB

    Install MariaDB on Windows/RedHat/Fedora/CentOS Linux/Debian/Ubuntu Linux Configure MariaDB to optimize data storage Administer users on MariaDB Learn how to utilize MariaDB to maintain a backup of ...

    node.js插件工具

    install-node-msi-version-on-linux-step1 install-node-msi-version-on-linux-step2 在完成下载后,将源码包名改为 'node'。 install-node-msi-version-on-linux-step3 修改目录权限: install-node-msi-...

    UE(官方下载)

    The selected text compare allows you to select portions of text between 2 files and execute a compare on ONLY the se Using the SSH/telnet console A tutorial for UltraEdit/UEStudio's SSH/telent ...

    MySQL 5.6 Reference Manual

    Table of Contents Preface, Notes, Licenses . . . . . . . . ....1. Licenses for Third-Party Components ....1.1. FindGTest.cmake License ....1.2. LPeg Library License ....1.3. LuaFileSystem Library License ....

    drupal 6.12

    For more information on setting file permissions, see "Modifying Linux, Unix, and Mac file permissions" (http://drupal.org/node/202483) or "Modifying Windows file permissions" ...

    hydra 7.2 win32

    Mobile systems based on Linux or Mac OS/X (e.g. Android, iPhone, Zaurus, iPaq) HOW TO USE ---------- Type "./configure", followed by "make" to compile hydra and then "./hydra -h" to see the command...

    php-5.6.37.tar.gz下载及php5.6源码安装说明

    yum install -y libxml2-devel openssl-devel libcurl-devel libjpeg-devel libpng-devel libicu-devel openldap-devel ./configure --prefix=/usr/local/php \ --with-config-file-path=/usr/local/php/etc \ --...

    docker搭建lnmp环境

    php算是这里面最难搞定的,因为我们需要额外的添加php扩展,虽然php的docker官方提供了`docker-php-ext-configure`, `docker-php-ext-install`, `docker-php-ext-enable`,还是有些扩展需要通过`手动编译`或者`pecl`...

Global site tag (gtag.js) - Google Analytics