Linux系统上安装MySQL数据库

来源:互联网 发布:淘宝买来的模板怎么装 编辑:程序博客网 时间:2024/06/07 01:28
原文:http://www.cnblogs.com/shihaiming/p/6251209.html

1.mysql5.7.17安装在/usr/local/mysql目录里面,也可以安装在其他地方
(安装包最好与Linux系统一样,eg;32位的就是“mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz”,官网可下载)

mkdir /usr/local/mysql

2.解压并复制

tar -xvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz(我是手动解压的)
mv mysql-5.7.17-linux-glibc2.5-x86_64/* /usr/local/mysql/  
3.创建data目录(很重要!)

mkdir /usr/local/mysql/data  
4.创建mysql用户和修改权限

groupadd mysql  
chown -R mysql.mysql /usr/local/mysql/  
5.初始化数据
进入到mysql文件下:cd /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)  
6. 复制配置文件到 /etc/my.cnf

cp -a ./support-files/my-default.cnf /etc/my.cnf (选择y)  
7. mysql的服务脚本放到系统服务中

cp -a ./support-files/mysql.server /etc/init.d/mysqld  
修改my.cnf文件    (vim /etc/my.cnf)
# These are commonly set, remove the # and set as required.  
basedir = /usr/local/mysql  
datadir = /usr/local/mysql/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   
 
 修改完了之后再最下面输入命令    :mq

8.启动mysql

service mysqld start   
ps -ef        #查看是启动
9.查看初始化自动生成的密码:   cat /root/.mysql_secret  (记住并复制下来,等会登陆mysql需要)

10.输入命令exit退出终端窗口,再次打开终端进入到mysql的文件夹下
进入mysql:bin/mysql -uroot -p  (把刚刚复制的密码粘贴上来)
[root@localhost ~]# cd /usr/local/mysql
[root@localhost mysql]# bin/mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.17

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

11.登录后重置root密码
mysql> set password for 'root'@localhost=password('123456');
Query OK, 0 rows affected, 1 warning (0.09 sec)

原创粉丝点击