Linux 下 mysql安装教程
1.下载安装包:
下载地址:http://dev.mysql.com/downloads/mysql/
我们已经下载好了mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz 直接用即可
2.将安装包拷贝到/usr/local/下(建议此目录),然后解压
[root@jdap01 local]# tar -zxvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
3.解压后重命名
[root@jdap01 local]# mv mysql-5.7.18-linux-glibc2.5-x86_64 mysql
4.新建用户和用户组,并授权
[root@jdap01 local]# groupadd mysql
[root@jdap01 local]# useradd msyql -g mysql
[root@jdap01 local]# chown mysql -R ./mysql/
[root@jdap01 local]# chgrp mysql -R ./mysql/
5.修改/usr/local/mysql/support-files目录下的mysql.server文件
设置值如下:
basedir= /usr/local/mysql
datadir= /usr/local/mysql/data
6.执行mysqld 脚本,初始化表空间
[root@jdap01 local]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir= /usr/local/mysql --datadir= /usr/local/mysql/data --character-set-server=utf8
如果报错,显示剩余空间不足,则将命令改为:
【报错内容如下:
2017-04-14T07:29:15.992800Z 0 [ERROR] InnoDB: Error number 28 means 'No space left on device'
2017-04-14T07:29:15.992830Z 0 [ERROR] InnoDB: Could not set the file size of './ibdata1'. Probably out of disk space
2017-04-14T07:29:15.992851Z 0 [ERROR] InnoDB: InnoDB Database creation was aborted with error Generic error. You may need to delete the ibdata1 file before trying to start up again.
2017-04-14T07:29:16.594143Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2017-04-14T07:29:16.594212Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2017-04-14T07:29:16.594226Z 0 [ERROR] Failed to initialize plugins.
2017-04-14T07:29:16.594233Z 0 [ERROR] Aborting
】
将命令修改为:
[root@jdap01 local]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir= /usr/local/mysql --datadir= /var/data --character-set-server=utf8
这里将会生成mysql数据库root用户的初始密码,注意保存!
然后回去修改/usr/local/mysql/support-files目录下的mysql.server文件
设置值如下:
**`basedir= /usr/local/mysql`**
**`datadir= /var/data`**
7.执行/usr/local/mysql/bin目录下的mysqld_safe脚本
[root@jdap01 local]# /usr/local/mysql/bin/mysqld_safe --user=mysql
[root@V_wangshenweb01 support-files]# ./mysql.server start
8.启动mysql客户端:
[root@jdap01 local]# ./mysql/bin/mysql -uroot -p
Enter password:
(输入上面保存的密码)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.18
Copyright (c) 2000, 2017, 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.
mysql>
安装成功!!
9.修改mysql的密码,命令如下:
mysql> SET PASSWORD FOR'root'@'localhost'=PASSWORD('mysql1234');
即为把密码修改为mysql1234开始使用mysql.
10.输入命令:
mysql> show databases;
显示:
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
成功!
‘