---
title: "Linux下安装mysql"
author: "eric_hwp"
date: "2017-05-03T17:13:49Z"
tags: []
categories: ["数据库"]
slug: "linux-mysql"
draft: false
lastmod: "2017-05-03T17:13:49Z"
id: 2372465
url: "https://eric-hwp.iteye.com/blog/2372465"
---

源码包下载：
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.23.tar.gz


# Preconfiguration setup
shell> groupadd mysql
shell> useradd -r -g mysql mysql
# Beginning of source-build specific instructions
shell> tar zxvf mysql-VERSION.tar.gz
shell> cd mysql-VERSION
shell> cmake -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1
shell> make
shell> make install
# End of source-build specific instructions
# Postinstallation setup
shell> cd /usr/local/mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql

重新登录
启动mysql服务
service mysql start
关闭mysql服务
service mysql stop

连接mysql
cd /usr/local/mysql/bin
./mysql -u root
修改root用户密码
update mysql.user set password=password('新密码') where user='root';
赋予权限给某用户，使其可以远程连接
GRANT ALL PRIVILEGES ON *.* TO 用户名@"%" IDENTIFIED BY '密码' WITH GRANT OPTION;
立即生效
flush privileges;