- 默认安装在
/usr/local/mysql
目录里,也可以安装在其他位置,官网下载地址:
- 创建文件夹,解压并移动到MySQL目录
[sudo] mkdir /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/* /usr/local/mysql/
- 创建data目录
mkdir /usr/local/mysql/data
- 创建
mysql
用户和修改权限
groupadd mysql
chown -R mysql:mysql /usr/local/mysql/
- 初始化数据
[root@localhost mysql] ./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
2016-01-20 02:47:35 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2016-01-20 02:47:45 [WARNING] The bootstrap log isn't empty:
2016-01-20 02:47:45 [WARNING] 2016-01-19T18:47:36.732678Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
2016-01-19T18:47:36.750527Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2016-01-19T18:47:36.750560Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
- 复制配置文件到
/etc/my.cnf
cp -a ./support-files/my-default.cnf /etc/my.cnf #选择y
- mysql的服务脚本放到系统服务中
cp -a ./support-files/mysql.server /etc/init.d/mysqld
修改/etc/my.cnf
文件
# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data # 修改data目录
port = 3306
# server_id = .....
socket = /tmp/mysql.sock
character-set-server = utf8
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
- 启动mysql
service mysqld start
ps -ef #查看是启动
- 查看初始化自动生成的密码:
cat /root/.mysql_secret #记住并复制下来,等会登陆mysql需要
- 进入mysql
bin/mysql -uroot -p #把刚刚复制的密码粘贴上来
- 登录后重置root密码
mysql> SET PASSWORD FOR 'root'@localhost = PASSWORD('123456');Query OK, 0 rows affected, 1 warning (0.00 sec)
网友评论