linux安装mysql

1.去官网地址下载mysql对应的版本:(不要去什么野鸡网站下载)

https://dev.mysql.com/downloads/mysql/

2.mysql安装包上传到服务器/usr/local 文件夹下

linux安装mysql_第1张图片

3.解压到 /usr/local 文件夹下

tar -xzvf mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz 

4.修改解压的文件夹为 mysql

mv mysql-5.6.46-linux-glibc2.12-x86_64 mysql

5.进入到/usr/local/mysql目录,执行添加MySQL配置的操作

cp support-files/my-medium.cnf /etc/my.cnf
cp support-files/my-default.cnf /etc/my.cnf

6.编辑/etc/my.cnf文件;

vim /etc/my.cnf
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
socket = /tmp/mysql.sock
character-set-server = utf8
skip-name-resolve
log-err = /usr/local/mysql/data/error.log
pid-file = /usr/local/mysql/data/mysql.pid

 

7.创建mysql用户组及用户并授权,在/usr/local/mysql目录下执行命令:

groupadd mysql
useradd -r -g mysql mysql
chown -R mysql .
chgrp -R mysql .

 

scripts/mysql_install_db --user=mysql
chown -R root .

 

chown -R mysql data

 (1)、注意,如果在执行命令时遇到以下错误:

FATAL ERROR: please install the following Perl modules before executing scripts/mysql_install_db:
Data::Dumper

  处理方式,执行以下命令:

yum -y install autoconf

 (2) 、注意,如果在执行命令时遇到以下错误:

Loaded plugins: fastestmirror, langpacks
Existing lock /var/run/yum.pid: another copy is running as pid 11685.
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: PackageKit
    Memory : 210 M RSS (1.1 GB VSZ)
    Started: Wed Oct 23 23:11:07 2019 - 15:12 ago
    State  : Sleeping, pid: 11685

处理方式,执行以下命令:

rm -f /var/run/yum.pid

8.初始化数据,在/usr/local/mysql执行命令:

./scripts/mysql_install_db --verbose --user=root --defaults-file=/etc/my.cnf --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql --pid-file=/usr/local/mysql/data/mysql.pid --tmpdir=/tmp

 

9.在/usr/local/mysql/bin执行命令:
 

./mysqld_safe --defaults-file=/etc/my.cnf --socket=/tmp/mysql.sock --user=root &

注意,如果光标停留在屏幕上,表示启动成功,不要执行退出操作,打开一个新的终端连接

10.打开一个新的终端设置开机启动,执行命令:

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysql
chmod 700 /etc/init.d/mysql
chkconfig --add mysqld
chkconfig --level 2345 mysqld on
chown mysql:mysql -R /usr/local/mysql/

 

11.重启linux

reboot

12.查看mysql状态,并添加远程访问权限

service mysqld status
ln  -s /usr/local/mysql/bin/mysql  /usr/bin

13.mysql安装完成修改root密码

登录mysql,执行下面命令
mysql -uroot -p 
密码为空直接回车,运行以下两条命令
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'tiger' with grant option;
Flush privileges;

 

你可能感兴趣的:(mysql,linux,mysql,mysql安装,虚拟机mysql安装)