您的位置:首页 > 运维架构 > Linux

在linux上安装mysql

2017-02-07 16:21 190 查看
#环境:centos 7

需要安装mysqlserver和mysql client

安装mysqlserver有两种方法:

在官网下载离线安装包,后缀是tar,解压以后在$MySQL/bin目录下会看到一些脚本,其中包括mysql_install_db,运行它来安装:管理InnoDB的系统表空间和相关数据结构、系统表、sys schema、mysql管理员账户等

通过yum

安装mysql client: yum install mysql

详细展开一下mysql_install_db:

5.7.5版本之前mysql_install_db是用Perl编写的,需要预先安装Perl;5.7.5之后通过C++编写,可以直接执行。

默认的安全设置:

5.7.5以及之后的版本:

默认创建一个账户’root’@’localhost’,并且随机生成密码,生成的随机密码默认在用户home目录下的.mysql_secret文件中,可以通过–random-password-file指定位置

不再在安装时创建匿名账户以及不再有任何test数据库可供访问

–admin-xxx选项可用于控制管理账户的特征

可以配置–insecure选项禁止随机密码的生成

5.7.4版本

默认创建一个账户’root’@’localhost’………..

同上

The –skip-random-passwords option is available to suppress random password generation, and to create a test database.

5.7.3及以前的版本are not secure default

多个管理员root账户在不设置密码的情况下被创建

有匿名账户被创建并且有test数据库可供访问

The –random-passwords option is available to generate random passwords for administrative accounts and mark them expired, and to not create anonymous-user accounts.

如何使用:

bin/mysql_install_db –datadir=path/to/datadir [other_options]

–datadir是必须配置的选项,datadir必须不存在,否则应该使用mysql_upgrade而不是install

如果install命令中途失败了则必须移除已经创建的部分datadir目录,才能重新执行install命令

用–basedir选项来指定mysql安装目录(可选项)

由于MySQL server —— mysqld之后在它运行时需要访问data directory,所以要么用同一个系统账户运行mysql_install_db和mysqld,要么用root账户运行install并且用–user选项显示指定mysqld运行时使用的linux系统账户。

shell> bin/mysql_install_db --user=mysql \
--basedir=/opt/mysql/mysql \
--datadir=/opt/mysql/mysql/data


其他选项 :https://dev.mysql.com/doc/refman/5.7/en/mysql-install-db.html

http://www.cnblogs.com/starof/p/4680083.html

通过yum安装:https://dev.mysql.com/doc/refman/5.7/en/linux-installation-yum-repo.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql linux