linux下的mysql的安装方式--yum--二进制
linux下的mysql的安装方式--yum--二进制
1.yum安装
yum方式
wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum -y install mysql-community-server
systemctl start mysql
systemctl status mysql 看一下状态
systemctl start mysql.service 设置自启动
ss -tulpn |grep mysql
数据库接口 3306
为root账户设置数据库密码
[root@node-1 ~]#mysql_secure_installation #初始化MySQL
Enter current password for root (enter for none): <---输入现在的root密码,因为我们还没设置,直接回车
Set root password? [Y/n] Y <---是否设定root密码,当然设置了,输入Y回车
New password: <---输入root密码,并回车,输入的过程中不会有任何显示
Re-enter new password: <---再次输入root密码,并回车,输入的过程中不会有任何显示
Remove anonymous users? [Y/n] Y <---是否删除匿名用户,删除,输入Y回车
Disallow root login remotely? [Y/n] Y <---是否删禁止root用户远程登录,当然禁止,输入Y回车
Remove test database and access to it? [Y/n] <---是否删除测试数据库test,看个人喜好
Reload privilege tables now? [Y/n] Y <---刷新权限,输入Y回车
最后出现:Thanks for using MySQL!
MySql密码设置完成,重新启动 MySQL:
tips:数据库密码一般设置就比较复杂的,在生产环境中,不过这里就不设置复杂的了,直接123
mysql -uroot -p"123" #创建一个root账户的数据库密码
create database wordpress; #新建一个数据库
show databases; #查看一下是否存在
2.二进制安装
(1).准备工作
前往mysql官网下载二进制安装包,https://dev.mysql.com/downloads/mysql/5.7.html#downloads(注意:选择操作系统时选Linux-Generic)。我这里下载的是mysql-5.7.26-linux-glibc2.12-x86_64。
Mysql5.7参考手册-2.2使用通用二进制文件在Unix/Linux上安装Mysql:https://dev.mysql.com/doc/refman/5.7/en/binary-installation.html
在下载和上传的过程中,可以先检查系统中的Mysql或mariadb,如果存在将其卸载
rpm -qa | grep mysql rpm -qa | grep mariadb mariadb-libs-5.5.56-2.el7.x86_64 yum -y remove mariadb-libs.x86_64
接着创建mysql的专用用户,官方使用的是/bin/false一样也可以。
useradd -M -s /sbin/nologin -r mysql //-M不创建主目录,-s /sbin/nologin不允许登录,-r创建的是系统用户
安装依赖包,CentOS7好像自带可以不装。
yum install libaio
官方说明:版本大于等于5.7.19,对通用Linux构建添加了对非统一内存访问(NUMA)的支持,该构建现在依赖于 libnuma
库。
(2).解压二进制包,创建数据目录,修改mysql文件所属主和所属组,然后初始化数据库
tar zxf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ //解压
cd /usr/local/
mv mysql-5.7.26-linux-glibc2.12-x86_64/ mysql //文件夹重命名,不然配置文件要写很长一段
cd mysql/
mkdir data //创建数据目录
chown -R mysql.mysql /usr/local/mysql/ //修改所属主和所属组
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data //初始化
2019-06-26T07:12:23.842578Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-06-26T07:12:25.699399Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-06-26T07:12:25.920250Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-06-26T07:12:25.998106Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: c03a1dc7-97e1-11e9-acca-000c29e6d627.
2019-06-26T07:12:26.041964Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-06-26T07:12:26.044143Z 1 [Note] A temporary password is generated for root@localhost: jcJ3Ncguf:ql //显示root@localhost第一次登录的随机密码
(3).编辑配置文件/etc/my.cnf
vim /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port=3306
socket=/usr/local/mysql/mysql.sock
character-set-server=utf8
log-error=/var/log/mysqld.log
pid-file=/tmp/mysqld.pid
[mysql]
socket=/usr/local/mysql/mysql.sock
[client]
socket=/usr/local/mysql/mysql.sock
(4).配置环境变量,并刷新
vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
. /etc/profile.d/mysql.sh //两种刷新方式,还可以使用source /etc/profile.d/mysql.sh
(5).生成启动脚本,并启动mysql
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
vim /etc/init.d/mysqld
basedir=/usr/local/mysql //在第46~47行 datadir=/usr/local/mysql/data
/etc/init.d/mysqld start
Starting MySQL. SUCCESS!
(6).测试,并修改root密码
mysql -uroot -p'123'
mysql> set password for root@localhost=password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> show variables like 'validate_password%'; //可以看到没有密码复杂度插件
Empty set (0.01 sec)
mysql> exit
Bye
mysql -uroot -p123456
mysql>