一、下载Linux和Windows平台下的安装包
1.Linux下的源码包下载地址
2.Linux下RPM包下载地址
3.Windows下MySQL二进制分发版(.msi安装文件)和免安装版(.zip压缩文件)下载地址
二、Linux安装MySQL
1.介绍
Linux安装MySQL,可以选择使用二进制和源码编译安装。
源码编译安装的优点:但由于二进制RPM包安装不能根据特定的业务场景,选择安装特定MySQL组件,所以选择源码编译安装MySQL数据库管理系统。
二进制RPM包安装的优点:RPM安装MySQL数据库管理系统简单,不需要源码编译安装特别繁琐的步骤
2.源码编译安装
1.安装依赖包
yum -y install ncurses-devel cmake
2.创建用户和组
groupadd mysql useradd -s /sbin/nologin mysql -M -g mysql
3.配置
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ -DMYSQL_DATADIR=/data/mysqldb/ -DMYSQL_UNIX_ADR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEAULT_COLLATION=utf8_general_ci -DEXTRA-CHARSETS=gbk,gb2312,utf8,ascii -DENABLED_LOCAL_INFILE=ON -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STOREAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITHOUT_PARTITION_STORAGE_ENGINE=1 -DWITH_FAST_MUIEXES=1 -DWITH_ZLIB=bundled -DENABLED_LOCAL_INFILE=1 -DWITH_PEADLINE=1 -DWITH_EMBEDDED_SERVER=1 -DWITH_DEBUG=0
4.安装
make -j3 && make install -j3
5.切换安装MySQL数据库目录
make -j3 && make install -j3
6.复制mysql配置文件
cp support-files/mysqlsammll.cnf /etc/my.cnf
7.给安装MySQL数据库目录指定用户和用户组
chown -R mysql.mysql /usr/local/mysql
8.配置环境变量
echo 'export PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile tail -1 /etc/profile source /etc/profile echo $PATH
9.初始化MySQL
bash /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysqldb/ --user=mysql
10.开户MySQL服务,并指定开机自启
/etc/init.d/mysqld start or service mysqld on chkconfig mysqld on
11.MySQL的root用户创建密码
mysqladmin -uroot password '123456'
12.root用户连接MySQL
mysql -uroot -p123456
3.RPM包的安装方式
1.解压从MySQL官网下载的MySQL压缩包
[root@ping ~]# tar -xf MySQL-5.5.59-1.el6.x86_64.rpm-bundle.tar -C /data
2.安装MySQL
[root@ping ~]# rpm -Uvh MySQL-*.rpm warning: MySQL-client-5.5.59-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ########################################### [100%] 1:MySQL-devel ########################################### [ 14%] 2:MySQL-client ########################################### [ 29%] 3:MySQL-test ########################################### [ 43%] 4:MySQL-embedded ########################################### [ 57%] 5:MySQL-shared-compat ########################################### [ 71%] 6:MySQL-shared ########################################### [ 86%] 7:MySQL-server ########################################### [100%] warning: user mysql does not exist - using root warning: group mysql does not exist - using root 180130 13:04:44 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap. 180130 13:04:44 [Note] /usr/sbin/mysqld (mysqld 5.5.59) starting as process 2240 ... 180130 13:04:45 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap. 180130 13:04:45 [Note] /usr/sbin/mysqld (mysqld 5.5.59) starting as process 2247 ... PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /usr/bin/mysqladmin -u root password 'new-password' /usr/bin/mysqladmin -u root -h ping.cn password 'new-password' Alternatively you can run: /usr/bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. Please report any problems at http://bugs.mysql.com/
二、Windows下安装MySQL
1.双击安装包,点击Next
2.选择自定义(Custom)安装类型
3.选择详细安装(Detailed Configuration)
4.选择服务器类型,“Developer Machine(开发测试类,mysql占用很少资源)”、“Server Machine(服务器类型,mysql占用较多资源)”、“Dedicated MySQL Server Machine(专门的数据库服务器,mysql占用所有可用资源)”,选择“Development Machine”
5.“Multifunctional Database(通用多功能型,好)”,“Transactional Database Only(服务器类型,专注于事务处理,一般)”、“Non-Transactional Database Only(非事务处理型,较简单,主要做一些监控、记数用,对MyISAM数据类型的支持仅限于non-transactional),选择“Transactional Database Only”
6.对InnoDB Tablespace进行配置,就是为InnoDB 数据库文件选择一个存储空间
7.mysql的访问量,同时连接的数目,“Decision Support(DSS)/OLAP(20个左右)”、“Online Transaction Processing(OLTP)(500个左右)”、“Manual Setting(手动设置,自己输一个数)”
8.将bin目录添加到PATH环境变量中
9.安装
10.查看MySQL允许哪些主机和用户登录
12.使用Navicat连接MySQL数据库
13.使用Navicat操作数据库