linux上安装mysql5.7.17

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_36245532/article/details/87918651

1、下载tar包,这里使用wget从官网下载

wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

2、将mysql安装到/usr/local/mysql下

# 解压

tar -xvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

# 移动

mv mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

# 重命名

mv /usr/local/mysql-5.7.17-linux-glibc2.5-x86_64  /usr/local/mysql

3、新建data目录

mkdir /usr/local/mysql/data

4、新建mysql用户、mysql用户组

# mysql用户组

groupadd mysql

# mysql用户

useradd mysql -g mysql

5、将/usr/local/mysql的所有者及所属组改为mysql

chown -R mysql.mysql /usr/local/mysql

6、配置

/usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data

# 如果出现以下错误:

2018-07-14 06:40:32 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2018-07-14 06:40:32 [ERROR]   Child process: /usr/local/mysql/bin/mysqldterminated prematurely with errno= 32
2018-07-14 06:40:32 [ERROR]   Failed to execute /usr/local/mysql/bin/mysqld --bootstrap --datadir=/usr/local/mysql/data --lc-messages-dir=/usr/local/mysql/share --lc-messages=en_US --basedir=/usr/local/mysql
-- server log begin --

-- server log end --

# 则使用以下命令:

/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize

# 如果出现以下错误:

/usr/local/mysql/bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory

或  bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

 此处需要注意记录生成的临时密码,如上文结尾处的:YLi>7ecpe;YP
#bin/mysql_ssl_rsa_setup  --datadir=/usr/local/mysql/data

 

# 完成后继续安装:

/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize

#修改系统配置文件

cd /usr/local/mysql/support-files

# cp my-default.cnf /etc/my.cnf
# cp mysql.server /etc/init.d/mysql

# vim /etc/init.d/mysql

修改以下内容:

basedir=/usr/local/mysql
datadir=/usr/local/mysql/data

# 则执行以下命令:

yum -y install numactl

 

7、开启服务

# 将mysql加入服务

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

# 开机自启

chkconfig mysql on

8、启动mysql

# /etc/init.d/mysql start

--登陆

# mysql -hlocalhost -uroot -p

  --如果出现:-bash: mysql: command not found

  --就执行: # ln -s /usr/local/mysql/bin/mysql /usr/bin --没有出现就不用执行

--输入第6步生成的临时密码

--修改密码

mysql> set password=password('root');

--设置root账户的host地址(修改了才可以远程连接)

mysql>grant all privileges on *.* to 'root'@'%' identified by 'root';
mysql>flush privileges;

 

9、将/etc/my.cnf中的skip-grant-tables删除

10、登录再次设置密码(不知道为啥如果不再次设置密码就操作不了数据库了)

/usr/local/mysql/bin/mysql -u root -p

 >>CREATE USER '用户'@'localhost' IDENTIFIED BY '修改后的密码'; 

>>exit;

 

展开阅读全文

没有更多推荐了,返回首页