码迷,mamicode.com
首页 > 数据库 > 详细

linux系统安装mysql

时间:2019-09-03 16:52:25      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:cto   ant   erro   检查   远程连接   进入   init   rpm   log   

1、将所需文件复制到linux系统

 技术图片

 

 

 2、检查安装环境,输入以下命令

# rpm -qa | grep mysql

如果有就卸载

rpm -e –nodeps mysql-libs-5.1.61-4.e16.x86_64

3、进入root,用 ll 查看

技术图片

 

4、解压

技术图片

 tar -zxvf /root/mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz -C /usr/local/

   文件夹改名mysql

技术图片

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

 

5、新建data目录

mkdir /usr/local/mysql/data

6、新建mysql用户、mysql用户组

# mysql用户组

groupadd mysql

# mysql用户

useradd mysql -g mysql

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

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

8、执行命令

/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

# 则使用以下命令:

/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

# 则执行以下命令:

yum -y install numactl

# 完成后继续安装:

/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

# 则执行以下命令:

yum install -y libaio

技术图片

 技术图片

 

 9、编辑/etc/my.cnf

vi /etc/my.cnf

[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/tmp/mysql.sock
user=mysql
port=3306
character-set-server=utf8
# 取消密码验证
skip-grant-tables
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# skip-grant-tables
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

按insert修改,结束后按esc,再:wq保存。

 10、开启服务

# 将mysql加入服务

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

# 开机自启

chkconfig mysql on

# 开启

service mysql start

11、设置密码

# 登录(由于/etc/my.cnf中设置了取消密码验证,所以此处密码任意)

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

# 操作mysql数据库

>>use mysql;

# 修改密码

>>update user set authentication_string=password(‘你的密码‘) where user=‘root‘;

>>flush privileges;

>>exit;

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

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

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

>>ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘修改后的密码‘;

>>exit;

14、允许远程连接

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

>>use mysql;

>>update user set host=‘%‘ where user = ‘root‘;

>>flush privileges;

>>exit;

15、添加快捷方式

ln -s /usr/local/mysql/bin/mysql /usr/bin

16、如果中途失败,需重新安装
find / -name mysql
然后 rm -rf 目录

linux系统安装mysql

标签:cto   ant   erro   检查   远程连接   进入   init   rpm   log   

原文地址:https://www.cnblogs.com/zmjc/p/11453563.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!