MySQL安装、基本账户安全(5.0以后版本)

安装;

安装后账户安全基础;


-----------MySQL 5.0以后版本的安装-----------


MySQL安装


安装包学习的必杀绝技――就是阅读包的安装说明(readme & install)文档。

----------

# rm /etc/my.cnf            (安装前执行一下)

----------



Mysql-5.0.40.tar.gz


1. Source Installation Overview(lines 74 of install-source)


系统默认可能会安装三个mysql的包:


mysql-libs


mysql


mysql-devel


从下往上依赖关系。


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 -r mysql


Shell> useradd -g mysql -M -r -s /sbin/nologin mysql



Shell> vi INSTALL-SOURCE


Shell> ./configure --prefix=/usr/local/mysql


Shell> echo $?


Shell> make


Shell> echo $?


Shell> make install


Shell> echo $?



Shell> cp support-files/my-medium.cnf /etc/my.conf


Shell> cd /usr/local/mysql


Shell> chown -R mysql .


Shell> chgrp -R mysql .


Shell> bin/mysql_install_db --user=mysql


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. Typical configure Options(lines 265 of  install-source)


Shell> ./configure --help


Shell> ./configure -h


Shell> ./configure --without-server


仅仅编译客户端程序


默认安装的目录/usr/local(数据目录/usr/local/var)。可以改写为:


Shell> ./configure --prefix=/usr/local/mysql


Shell> ./configure --prefix=/usr/local/ --localstatedir=/usr/local/mysql/data


使用unix的套接字方式连接数据库:


Shell> ./configure --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock


gcc,没有c++库,可以使用gcc来作为c++的编译器:


Shell> CC=gcc CXX=gcc ./configure



Shell> ./configure --with-charset=gb2312


Shell> ./configure --with-charset=utf8


Shell> ./configure --with-charset=latin1(这个是默认值)


Shell> ./configure --with-collation=latin1_swedish_ci(这个是排序方法的默认值)


Shell> ./configure --with-extra-charsets=(空格分开)


Shell> ./configure --with-extra-charsets=all



重新编译一个源码树时:


Shell> rm config.cache


Shell> make clean


Shell> make dist


Mysql-5.1.72.tar.gz


安装方法跟上边的大同小异。



Mysql-5.5.22.tar.gz


1. Installing MySQL from Generic Binaries on Unix/Linux


系统默认可能会安装三个mysql的包:


mysql-libs


mysql


mysql-devel


从下往上依赖关系。


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. Installing MySQL from Source


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


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


Shell>


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.rpm



Start from a source RPM,run:


Shell> rpmbuild --rebuild --clean MySQL-VERSION.src.rpm


Shell>



Cmake-2.8.12.tar.gz


Shell> vi Readme.txt


Shell> ./bootstrap


Shell> make


Shell> make install


Mysql-5.5.34.tar.gz


1. Installing MySQL on Unix/Linux Using Generic Binaries


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. Installing MySQL Using a Standard Source Distribution


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 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


Mysql-5.6.14.tar.gz


同上



-----------MySQL 安装完成后的帐号安全问题-----------
   问题描述

   刚安装好的系统, root 默认密码为空;默认空用户(空密码)也可以在本地登录;
   查看系统中有那些账户:
   mysql> select host,user,password from mysql.user;

wKioL1NpcLHCUzP4AABpQ7zl98Y730.jpg


   显示结果,表示有多个 root 用户;有两个 空用户。没有一个有密码。
   这就需要为每一个用户设定密码;同样需要为空用户设定密码,或者删除。

   mysql.db 中的某些行,允许所有用户(包括没有密码的空账户;anonymous)访问测试数据库或者其
   他以 “test_” 开头的数据库。(这个默认设置是为了测试的)

   -------
   修改 root 密码

   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;

wKiom1NpelSA6mZrAADlonZSXLI953.jpg


   shell> mysql -u root
   mysql> UPDATE mysql.user SET password = PASSWORD('newpwd)
       -> WHERE user = 'root';
   mysql> FLUSH PRIVILEGES;        (没有这步,就得重启后才能生效)

   shell> mysqladmin -u root password "newpwd"
   shell> mysqladmin -u root -h host_name password "newpwd"
       mysqladmin 无法对127.0.0.1起作用。
   shell> mysqladmin -u root -p shutdown

   -------
   修改 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;

wKiom1NpcZ2iAsmYAABZfIxGefY124.jpg


   -------
   拒绝任意用户访问测试数据库

   shell> mysql -u root -p
   mysql> DELETE FROM mysql.db WHERE db LIKE 'test%';
   mysql> FLUSH PRIVILEGES;

   mysql> DROP DATABASE test;    (* 再进一步,连测试库都干掉)

-----------------------------
使用 RPM 包安装数据库

   RPM 包可以是官方提供的,也可以是其他作者提供的;可能有所不同(文件结构)。
   标准安装,需要 MySQL-server & MySQL-client 。(其他的包在标准安装中不需要)

   4109 行有关于各种包(名称)代表含义的详细说明。(包对 CPU 是有选择的 4208 )

   查看 RPM 包里的文件:
   shell> rpm -qpl MySQL-server-VERSION.glibc23.i386.rpm

   -------
   * Red Hat Linux, Fedora, CentOS

   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 dynamically
      linked MySQL library for your client applications. It is the
      server that is most critical for performance.

    * For a connection from a client to a server running on the same
      host, if you connect using TCP/IP rather than a Unix socket
      file, performance is 7.5% slower. (On Unix, if you connect to
      the host name localhost, MySQL uses a socket file by default.)

    * For TCP/IP connections from a client to a server, connecting
      to a remote server on another host is 8% to 11% slower than
      connecting to a server on the same host, even for connections
      faster than 100Mb/s Ethernet.

    * When running our benchmark tests using secure connections (all
      data 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 is
      4% faster than one compiled with gcc 3.2.

    * On a Sun UltraSPARC-IIe, a server compiled with Forte 5.0 is
      4% 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. 



这段保留一点原汁原味


本文出自 “小崔的实验笔记” 博客,谢绝转载!

你可能感兴趣的:(source,bin,cmake,configre)