关闭

mysql安装

标签: mysql
319人阅读 评论(0) 收藏 举报
分类:

这里写图片描述
这里写图片描述

win下卸载:
由于是压缩版安装,因此删除的时候不用去应用中心卸载,只需删除注册表的相关信息。
卸载服务:

mysqld --remove mysql

这里写图片描述
这里写图片描述
将解压的mysql目录删除就完成了。

win下安装:
mysql-5.7.17-winx64版本:
将下载的压缩包解压到安装目录:
1、
这里写图片描述
2、添加环境变量:
这里写图片描述
这里写图片描述

3、在cmd中初始化安装

mysqld --initialize-insecure --user=mysql

添加到系统服务:

mysqld --install

4、查看版本,启动服务:

mysql --version
net start mysql

mysql-5.6.13-winx64版本
此版本跟之前的安装有点区别。
1、不需要创建data
2、不需要修改my-default.ini
安装命令:
mysqld –console
第一次启动时,会在/data 目录下创建需要的所需文件
这里写图片描述
第二次执行 mysqld –console
这里写图片描述
将MySql设置成window服务
这里写图片描述

=================分割线==========================
linux下的安装。
卸载mysql:

 yum remove  mysql mysql-server mysql-libs mysql-server;
 find / -name mysql 将找到的相关东西delete掉   rm -rf ./var/lib/mysql;
 rpm -qa|grep mysql(查询出来的东东yum remove掉)
 卸载方法
 rpm -e --nodeps (包名)

1、在线yum安装:

1、查看有没有安装过:
          yum list installed mysql*
          rpm -qa | grep mysql*
2.查看有没有安装包:
          yum list mysql*
3.安装mysql客户端:
          yum install mysql
4.安装mysql 服务器端:
          yum install mysql-server
          yum install mysql-devel

启动mysql服务:

          service mysqld start或者/etc/init.d/mysqld start

数据库字符集设置

     mysql配置文件/etc/my.cnf中加入default-character-set=utf8

2、离线安装:
二进制编码安装:
下载二进制编码文件
这里写图片描述
复制到linux文件下

创建软件存放目录:
mkdir -p /home/software/mysql
创建mysql用户
groupadd mysql
useradd -g -r mysql mysql
解压下载的tar包,解压完后会有两个gz包,test的gz我们不用
tar -xvf mysql-5.7.17-linux-glibc2.5-x86_64.tar 
tar -zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
将解压后的包移动到/usr/loacl下并将名称改为mysql
mv mysql-5.7.17-linux-glibc2.5-x86_64 /usr/local/mysql
cd /usr/local/mysql/
创建data与logs目录
mkdir /usr/local/data
mkdir /usr/local/logs
更改目录权限
chown -R mysql:mysql /usr/local/mysql
创建my.cnf文件
vi /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[client]
port=3306
socket=/tmp/mysql.sock

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....


# 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 

basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
pid-file=/usr/local/mysql/data/mysql.pid
log_error=/usr/local/mysql/logs/mysql-error.log

#default-character-set=utf8
character_set_server=utf8
port=3306
server_id=10
user=mysql

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 




初始化mysql:

cd /usr/local/mysql/

bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
注意:执行完上面这步,在mysql的logs目录下应该会生成mysql-error.log,打开会看到生成的初始化密码
 A temporary password is generated for root@localhost: jfH_e0duDORh

注意:如果没有生成或者没有生成密码,一定是上面的步骤没有执行对,将mysql文件删掉,重新解压拷贝,按照上面的流程走

如果生成了初始化密码接着执行:

bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data

配置启动文件:

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
映射一个链接到/usr/bin目录下
ln -s /usr/local/mysql/bin/mysql /usr/bin

启动服务:

service mysql start
mysql -u root -p

输入之前初始化的密码就OK。
修改初始化密码:
service mysql stop
/usr/local/mysql/bin/mysqld_safe –skip-grant-tables

重新打开一个SSH

mysql
use mysql
update user set authentication_string=password('123456') where user='root';
flush privileges;
exit

这样改完如果不行就登陆进去直接改:

alter user 'root'@'localhost' identified by 'root';
flush privileges;
exit

======================分割线======================

编译安装:
装备条件:
下载源
这里写图片描述

wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17.tar.gz

下载boost

wget http://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz

将boost解压

 tar -zxvf boost_1_59_0.tar.gz
 mv boost_1_59_0 /usr/local/boost

下载依赖

yum install cmake gcc-c++ ncurses-devel perl-Data-Dumper boost boost-doc boost-devel

添加用户

groupadd mysql          
useradd -g mysql mysql  

将源码包解压:

tar -zxvf mysql-5.7.17.tar.gz
cd mysql-5.7.17

5.7以后都是用cmake命令

cmake -DCMAKE_INSTALL_PREFIX=/home/mysql -DMYSQL_DATADIR=/home/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost

编译(编译需要很久,尽量将虚拟机的性能调到最大):

make && make install

编译完后给目录设置权限:

chown -R mysql:mysql /home/mysql

初始化数据库(这一步执行完会生成初始密码,一定要记住)

/home/mysql/bin/mysqld --initialize --user=mysql --basedir=/home/mysql --datadir=/home/mysql/data

初始2:

bin/mysql_ssl_rsa_setup --datadir=/home/mysql/data

配置启动文件:

cp /home/mysql/support-files/mysql.server /etc/init.d/mysql
映射一个链接到/usr/bin目录下
ln -s /home/mysql/bin/mysql /usr/bin

设置配置文件:

mv /etc/my.cnf /etc/my.cnf.bak
cp /home/mysql/support-files/my-default.cnf /etc/my.cnf

my.cnf参考

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[client]
port=3306
socket=/tmp/mysql.sock
default-character-set=utf8
[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....

# 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 


basedir=/home/mysql
datadir=/home/mysql/data
socket=/tmp/mysql.sock
#pid-file=/home/mysql/data/mysql.pid
pid-file=/home/mysql/data/localhost.localdomain.pid
#log_error=/home/mysql/logs/mysql-error.log

character_set_server=utf8
port=3306
server_id=10
user=mysql

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

起动服务:

service mysql start

设置初始密码参考上面

=========================设置开机自动启动============

chmod +x /etc/init.d/mysql
chkconfig –add mysql
chkconfig mysql on 或者chkconfig –levels 235 mysql on

设置远程连接:
grant all privileges on . to ‘root’@’%’ identified by ‘123456’ with grant option;

flush privileges;

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:31158次
    • 积分:873
    • 等级:
    • 排名:千里之外
    • 原创:57篇
    • 转载:4篇
    • 译文:0篇
    • 评论:5条
    文章分类
    最新评论