欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 运维知识 > 数据库 >内容正文

数据库

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

发布时间:2025/4/5 数据库 35 豆豆
生活随笔 收集整理的这篇文章主要介绍了 MySQL安装、基本账户安全(5.0以后版本) 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

博文目录:

  1.Mysql-5.0.40.tar.gz
   Mysql-5.1.72.tar.gz
  2.Mysql-5.5.22.tar.gz
  3.Mysql-5.5.34.tar.gz

  4.Mysql-5.6.36tar.gz

附:

  1.账号安全



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


MySQL安装


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

----------

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

----------



1.Mysql-5.0.40.tar.gz


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


系统默认可能会安装三个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 -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


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

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

_____________



2.Mysql-5.5.22.tar.gz


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=



附:1.账号安全


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

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

无用户名、密码本地登录 [work@tri ~]$ mysql 使用有用户名的方式登录 [work@tri ~]$ mysql -u root -h localhost mysql> select host,user,password from mysql.user; mysql> select host,user,password from mysql.user; +-----------+------+----------+ | host      | user | password | +-----------+------+----------+ | localhost | root |          | | tri       | root |          | | 127.0.0.1 | root |          | | ::1       | root |          | | localhost |      |          | | tri       |      |          | +-----------+------+----------+ 6 rows in set (0.00 sec)


   显示结果,表示有多个 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;


 

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;


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

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

这段保留一点原汁原味


转载于:https://blog.51cto.com/sunnybay/1375274

总结

以上是生活随笔为你收集整理的MySQL安装、基本账户安全(5.0以后版本)的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。