实验环境:
Ubuntu 14.04
mysql 5.7.9
一、先卸载之前的mysql
请参考
http://dahui09.blog.51cto.com/10693267/1718431
二、下载安装包
地址:http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.9-linux-glibc2.5-x86_64.tar
三、安装
cd /usr/loca/
1.先压缩
# tar xvf mysql-5.7.9-linux-glibc2.5-x86_64.tar
2.解压 )
# tar zxvf mysql-5.7.9-linux-glibc2.5-x86_64.tar.gz
3.改名、切换路径
# mv mysql-5.7.9-linux-glibc2.5-x86_64 mysql # cd mysql/
4.创建data目录(5.7.9里面没有data目录),用户合组
#mkdir data #useradd -r -M -s /sbin/nologin mysql #chown -R mysql.mysql /usr/local/mysql-5.7.9 #chown -R mysql.mysql /usr/local/mysql
5.数据库初始化(可能有警告没事搭)
bin/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
# ./bin/mysqld_safe –user=mysql &
6.运行mysql,报错出现错误(ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock‘),创建一个软连接
# service mysql restart # /usr/local/mysql# ln -s /tmp/mysql.sock /var/run/mysqld/mysqld.sock
7.在配置文件里添加
skip-grant-tables -- 跳过权限
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
8.添加启动项
cp support-files/mysql.server /etc/init.d/mysql
9.配置Mysql系统环境变量,编辑/etc/profile文件
找到export PATH在前面添加
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:${MYSQL_HOME}/bin
添加Mysql环境变量之后,使用source /etc/profile命令使环境变量及时生效
四、设置mysql root 密码
> UPDATE user SET authentication_string = password ( ‘new-password’ ) WHERE User = ‘root‘; > flush privileges;
如果输完密码报错,提示密码过期(ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords.)
> UPDATE user SET password_expired = ‘Y‘ WHERE User = ‘root‘;