MySQL数据库从入门到实战
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL数据库从入门到实战相关的知识,希望对你有一定的参考价值。
MySQL安装(5.6.36)(CentOS6)
(1)准备工作:(关闭selinux,防火墙)
(2)开始安装
- 1、安装依赖包(配置好yum源)*
yum install -y ncurses-devel libaio-devel
rpm -qa ncurses-devel libaio-devel
vi /etc/yum.conf
keepcache=1 将网络yum源使用过的软件包保存下来
cachedir=/var/cache/yum/$basearch/$releasever 保存在这个位置
2.安装cmake
yum install cmake -y
rpm -qa cmake
3.设置用户
useradd -s /sbin/nologin -M mysql
id mysql
4.解压安装
cd /home/oldboy/tools/
wget -q http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36.tar.gz
ls -l mysql-5.6.36.tar.gz
尽量去官方下载
[[email protected] data]# md5sum mysql-5.6.36.tar.gz
a36a241164c78286993cbe1079626cdd mysql-5.6.36.tar.gz
[[email protected] data]#
tar xf mysql-5.6.36.tar.gz
cd mysql-5.6.36
cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.6.36 \
-DMYSQL_DATADIR=/application/mysql-5.6.36/data \
-DMYSQL_UNIX_ADDR=/application/mysql-5.6.36/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_ZLIB=bundled \
-DWITH_SSL=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_DEBUG=0
make && make install
ln -s /application/mysql-5.6.36/ /application/mysql
5.初始化及配置数据库
cp support-files/my*.cnf /etc/my.cnf
下面两步必做,不然初始化出错
mkdir -p /application/mysql-5.6.36/tmp
chown -R mysql.mysql /application/mysql-5.6.36/tmp
/application/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data --user=mysql
chown -R mysql.mysql /application/mysql/
cp support-files/mysql.server /etc/init.d/mysqld
chmod 700 /etc/init.d/mysqld
/etc/init.d/mysqld start
chkconfig mysqld on
chkconfig --list mysqld
netstat -lntup|grep 3306
echo ‘PATH=/application/mysql/bin/:$PATH‘ >>/etc/profile
source /etc/profile
mysql
设置密码:
mysqladmin -u root password ‘123456‘
mysql -uroot -poldboy123
清理用户及无用数据库(基本优化)
select user,host from mysql.user;
drop user ‘‘@‘db02‘;
drop user ‘‘@‘localhost‘;
drop user ‘root‘@‘db02‘;
drop user ‘root‘@‘::1‘;
select user,host from mysql.user;
drop database test;
show databases;
常见问题:
故障:ERROR! The server quit without updating PID file
1.权限.chown -R mysql.mysql
2.killall mysqld
3.重新初始化数据.
4.运行1年了,出问题(非法(断电)关机或者非法关数据库,例如kill -9).
以上是关于MySQL数据库从入门到实战的主要内容,如果未能解决你的问题,请参考以下文章