2.1.Installing MySQL from Generic Binaries on Unix/Linux
系统默认可能会安装三个mysql的包: mysql-libs mysql mysql-devel 从下往上依赖关系。
二进制文件安装mysql
检查环境
Shell> rpm -aq | grep mysql
Shell> rpm -ql mysql
Shell> rpm -qf /etc/my.conf
Shell> rpm -qc mysql-libs
Shell> rpm -qR mysql-libs
Shell> rpm -qd mysql
Shell> rpm -qi mysql
Shell> netstat -nlt
Shell> find / -name mysql
Shell> find / -name my.conf
Shell> cat /etc/passwd | grep mysql
Shell> cat /etc/group |
Shell> rpm -qa | grep gcc
Shell> rpm -qa | grep make
Shell> ls /home添加用户
Shell> groupadd mysql
Shell> useradd -r -g mysql -M -s /sbin/nologin mysql开始安装
Shell> cd /usr/local
Shell> tar -zxvf ……
Shell> cd mysql
Shell> chown -R mysql .
Shell> chgrp -R mysql .
初始化数据库
Shell> scripts/mysql_install_db --user=mysql
Shell> chown -R root .
Shell> chown -R mysql data配置操作
Shell> cp support-files/my-medium.cnf /etc/my.cnf
Shell> cp support-files/mysql.server /etc/init.d/mysqld
Shell> chmod 755 /etc/init.d/mysqld
启动服务
Shell> bin/mysqld_safe --user=mysql --datadir=/dell/mysql_data
2.2.Installing MySQL from Source
源码包安装mysql
检查环境
Shell> rpm -aq | grep mysql
Shell> rpm -ql mysql
Shell> rpm -qf /etc/my.conf
Shell> rpm -qc mysql-libs
Shell> rpm -qR mysql-libs
Shell> rpm -qd mysql
Shell> rpm -qi mysql
Shell> netstat -nlt
Shell> find / -name mysql
Shell> find / -name my.conf
Shell> cat /etc/passwd | grep mysql
Shell> cat /etc/group |
Shell> rpm -qa | grep gcc
Shell> rpm -qa | grep make
Shell> ls /home添加用户
Shell> groupadd mysql
Shell> useradd -r -g mysql -M -s /sbin/nologin mysql配置、编译
Shell> ccmake .(先进行交互式配置)
Shell> cmake .
Shell> make
Shell> make install
Shell> cd /usr/local/mysql
Shell> chown -R mysql .
Shell> chgrp -R mysql .
初始化数据库
Shell> scripts/mysql_install_db --user=mysql
Shell> chown -R root .
Shell> chown -R mysql data
Shell> cp support-files/my-medium.cnf /etc/my.cnf
Shell> cp support-files/mysql.server /etc/init.d/mysqld
Shell> chmod 755 /etc/rc.d/init.d/mysqld
启动服务
Shell> bin/mysqld_safe --user=mysql --datadir=/dell/mysql_data
2.3.To list the configuration options,use one of the following.
Shell> cmake . -L# overview
Shell> cmake . -LH# overview with help text
Shell> cmake . -LAH# all params with help text
Shell> ccmake .# interactive display
Shell> make clean
Shell> rm CMakeCache.txt
2.4.rpm
To see all files in an RPM packet,run a command like this:
Shell> rpm -qpl MySQL-server-VERSION.glibc23.i386.rpm
Shell> rpm -ivh MySQL-server-VERSION.glibc23.i386.rpm
Shell> rpm -ivh MySQL-client-VERSION.glibc23.i386.rpmStart from a source RPM,run:
Shell> rpmbuild --rebuild --clean MySQL-VERSION.src.rpm
2.5.安装Cmake-2.8.12.tar.gz
Shell> vi Readme.txt
Shell> ./bootstrap
Shell> make
Shell> make install
3.Mysql-5.5.34.tar.gz
3.1. Installing MySQL on Unix/Linux Using Generic Binaries
二进制包安装mysql
检查当前环境配置
Shell> rpm -aq | grep mysql
Shell> rpm -ql mysql
Shell> rpm -qf /etc/my.conf
Shell> rpm -qc mysql-libs
Shell> rpm -qR mysql-libs
Shell> rpm -qd mysql
Shell> rpm -qi mysql
Shell> netstat -nlt
Shell> find / -name mysql
Shell> find / -name my.conf
Shell> cat /etc/passwd | grep mysql
Shell> cat /etc/group |
Shell> rpm -qa | grep gcc
Shell> rpm -qa | grep make添加用户
Shell> groupadd mysql
Shell> useradd -r -g mysql -M -s /sbin/nologin mysql
Shell> cd /usr/local
开始安装
Shell> tar -zxvf ……
Shell> cd mysql
设定目录权限
Shell> chown -R mysql .
Shell> chgrp -R mysql .
初始化数据库
Shell> scripts/mysql_install_db --user=mysql
设定库文件目录权限
Shell> chown -R root .
Shell> chown -R mysql data
添加配置文件
Shell> cp support-files/my-medium.cnf /etc/my.cnf
Shell> cp support-files/mysql.server /etc/init.d/mysqld
Shell> chmod 755 /etc/init.d/mysqld
启动服务
Shell> bin/mysqld_safe --user=mysql --datadir=/dell/mysql_data
3.2.Installing MySQL Using a Standard Source Distribution
源码包安装mysql
Shell> rpm -aq | grep mysql
Shell> rpm -ql mysql
Shell> rpm -qf /etc/my.conf
Shell> rpm -qc mysql-libs
Shell> rpm -qR mysql-libs
Shell> rpm -qd mysql
Shell> rpm -qi mysql
Shell> netstat -nlt
Shell> find / -name mysql
Shell> find / -name my.conf
Shell> cat /etc/passwd | grep mysql
Shell> cat /etc/group |
Shell> rpm -qa | grep gcc
Shell> rpm -qa | grep make
Shell> ls /homeShell> groupadd mysql
Shell> useradd -r -g mysql -M -s /sbin/nologin mysqlShell> cd mysql
Shell> ccmake .(没有这一步也过去了)
Shell> cmake .
Shell> make
Shell> make install
Shell> cd /usr/local/mysql
Shell> chown -R mysql .
Shell> chgrp -R mysql .
Shell> scripts/mysql_install_db --user=mysql
Shell> chown -R root .
Shell> chown -R mysql data
Shell> cp support-files/my-medium.cnf /etc/my.cnf
Shell> cp support-files/mysql.server /etc/init.d/mysqld
Shell> chmod 755 /etc/init.d/mysqld
Shell> bin/mysqld_safe --user=mysql --datadir=/dell/mysql_data
4.Mysql-5.6.36.tar.gz
二进制包安装mysql
添加用户
[root@tri blog]# groupadd -g 51 mysql
[root@tri blog]# useradd -r -u 51 -g 51 -d /data02/blog/mysql_data -s /sbin/nologin mysql开始安装
[root@tri local]# tar -xf /opt/data01/tars/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
[root@tri local]# ln -s mysql-5.6.36-linux-glibc2.5-x86_64/ mysql
[root@tri local]# cd mysql
[root@tri mysql]# chown -R mysql:mysql .
[root@tri mysql]# scripts/mysql_install_db --user=mysql
[root@tri mysql]# chown -R root .
[root@tri mysql]# chown -R mysql data/
标准启动
[root@tri mysql]# bin/mysqld_safe --user=mysql
直接启动
[root@tri mysql]# bin/mysqld_safe --user=mysql --bind-address=127.0.0.1 --port 3333解包后查看文件,编译时配置“-prefix=”
[root@tri mysql]# vi docs/INFO_BIN
CMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql
MYSQL_DATADIR:PATH=/usr/local/mysql/data添加启动时打开服务
[root@tri mysql]# cp support-files/mysql.server /etc/init.d/mysql
打开上述文件(提示配置文件、主目录、数据目录)
[root@tri mysql]# vi /etc/init.d/mysql
# If you install MySQL on some other places than /usr/local/mysql, then you
# have to do one of the following things for this script to work:
#
# - Run this script from within the MySQL installation directory
# - Create a /etc/my.cnf file with the following information:
# [mysqld]
# basedir=<path-to-mysql-installation-directory>
# - Add the above to any other configuration file (for example ~/.my.ini)
# and copy my_print_defaults to /usr/bin
# - Add the path to the mysql-installation-directory to the basedir variable
# below.
#
# If you want to affect other MySQL variables, you should make your changes
# in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.basedir=
datadir=
shell> mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpwd');
mysql> SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('newpwd');
mysql> SET PASSWORD FOR 'root'@'host_name' = PASSWORD('newpwd');
mysql> select host,user,password from mysql.user;
修改 anonymous 密码
shell> mysql -u root -p
mysql> SET PASSWORD FOR ''@'localhost' = PASSWORD('newpwd');
mysql> SET PASSWORD FOR ''@'host_name' = PASSWORD('newpwd');shell> mysql -u root -p
mysql> UPDATE mysql.user SET password = PASSWORD('newpwd')-> WHERE user = '';
mysql> FLUSH PRIVILEGES;
-------
删除 anonymous 用户
shell> mysql -u root -p
mysql> DROP USER ''@'localhost';
mysql> DROP USER ''@'host_name';
mysql> select host,user,password from mysql.user;
------- 拒绝任意用户访问测试数据库
shell> mysql -u root -p
mysql> DELETE FROM mysql.db WHERE db LIKE 'test%';
mysql> FLUSH PRIVILEGES;mysql> DROP DATABASE test; (* 再进一步,连测试库都干掉)
root-shell> yum install mysql mysql-server mysql-libs
root-shell> service mysqld start
root-shell> chkconfig --levels 235 mysqld on
------- Debian,Ubuntu,Kubuntu
root-shell> apt-get install mysql-client-5.1 mysql-server-5.1
root-shell> service mysql start | stop
----------------------------- 优化从编译个出色的mysqld开始
使用最好的编译器、和最佳的编译选项;使用静态模板编译。这个很重要,性能能提升10-30%。直接在官网下载的二进制包,包含所有的字符集;自己编译可以选择需要的字符集。Here is a list of some measurements that we have made:* If you link dynamically (without -static), the result is 13%slower on Linux. Note that you still can use a dynamicallylinked MySQL library for your client applications. It is theserver that is most critical for performance.* For a connection from a client to a server running on the samehost, if you connect using TCP/IP rather than a Unix socketfile, performance is 7.5% slower. (On Unix, if you connect tothe host name localhost, MySQL uses a socket file by default.)* For TCP/IP connections from a client to a server, connectingto a remote server on another host is 8% to 11% slower thanconnecting to a server on the same host, even for connectionsfaster than 100Mb/s Ethernet.* When running our benchmark tests using secure connections (alldata encrypted with internal SSL support) performance was 55% slower than with unencrypted connections.* On a Sun UltraSPARC-IIe, a server compiled with Forte 5.0 is4% faster than one compiled with gcc 3.2.* On a Sun UltraSPARC-IIe, a server compiled with Forte 5.0 is4% faster in 32-bit mode than in 64-bit mode.* Compiling on Linux-x86 using gcc without frame pointers(-fomit-frame-pointer or -fomit-frame-pointer -ffixed-ebp)makes mysqld 1% to 4% faster.