Install and Configure MySQL on Linux

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Sure! Here are the steps to compile and install MySQL 8.0 on Linux: 1. Download the MySQL source code from the MySQL website. Make sure to choose the appropriate package for your Linux distribution. 2. Install the necessary dependencies. This may vary depending on your Linux distribution, but typically, you will need packages like `build-essential`, `cmake`, `libssl-dev`, `libncurses5-dev`, `libboost-dev`, etc. You can use your package manager (e.g., apt-get, yum) to install them. 3. Extract the downloaded MySQL source code package. 4. Create a build directory and navigate into it: ``` mkdir mysql-build cd mysql-build ``` 5. Configure the build using cmake. Replace `<path-to-source-directory>` with the path to the extracted MySQL source code: ``` cmake <path-to-source-directory> ``` 6. Build MySQL using make: ``` make ``` 7. Install MySQL: ``` sudo make install ``` 8. Initialize the MySQL data directory: ``` sudo mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data ``` 9. Set the ownership and permissions for the MySQL data directory: ``` sudo chown -R mysql:mysql /usr/local/mysql/data sudo chmod -R 750 /usr/local/mysql/data ``` 10. Start the MySQL server: ``` sudo /usr/local/mysql/support-files/mysql.server start ``` 11. Secure the installation by running the MySQL secure installation script: ``` sudo mysql_secure_installation ``` 12. Follow the prompts to set a root password, remove anonymous users, disable remote root login, etc. That's it! You have successfully compiled and installed MySQL 8.0 on your Linux system.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值