mysql之source编译,二进制安装以及权限分配等
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql之source编译,二进制安装以及权限分配等相关的知识,希望对你有一定的参考价值。
mysql是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下公司,由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,一般中小型网站的开发都选择 MySQL 作为网站数据库。
mysql内部结构:
两种安装方式:源码编译,二进制安装。
依赖:
[[email protected] tools]# yum install -y cmake [[email protected] tools]# yum install readline-devel zlib-devel openssl-devel -y
添加mysql用户组:
[[email protected] tools]# groupadd -r -g 306 mysql [[email protected] tools]# useradd -g mysql -u 306 -r -s /sbin/nologin mysql
创建数据与日记存储目录:
[[email protected] tools]# mkdir /mydata/mysql/data -pv mkdir: created directory `/mydata/mysql‘ mkdir: created directory `/mydata/mysql/data‘ [[email protected] tools]# mkdir /mydata/mysql/log -pv mkdir: created directory `/mydata/mysql/log‘ [[email protected] mysql-5.5.48]# chown -R mysql.mysql /mydata/mysql/
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql5.5.48 -DMYSQL_DATADIR=/mydata/mysql/data -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
[[email protected] mysql-5.5.48]# make [[email protected] mysql-5.5.48]# make install
初始化:
[[email protected] local]# cd /usr/local [[email protected] local]# chown -R mysql.mysql mysql5.5.48/ [[email protected] local]# cd mysql5.5.48/ [[email protected] mysql5.5.48]# scripts/mysql_install_db --user=mysql --datadir=/mydata/mysql/data/
添加控制脚本:
[[email protected] mysql5.5.48]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld [[email protected] mysql5.5.48]# chmod +x /etc/rc.d/init.d/mysqld
配置文件:
[[email protected] mysql5.5.48]# cp support-files/my-large.cnf /etc/my.cnf [[email protected] mysql5.5.48]# vim /etc/my.cnf datadir=/mydata/mysql/data innodb_file_per_table=ON log-bin=/mydata/mysql/log/mysql-bin
path添加:
[[email protected] mysql5.5.48]# vim /etc/profile.d/mysql.sh export PATH=/usr/local/mysql5.5.48/bin:$PATH [[email protected] mysql5.5.48]# . /etc/profile.d/mysql.sh
启动脚本:
[[email protected] mysql5.5.48]# /etc/init.d/mysqld start Starting MySQL.. SUCCESS! [[email protected] mysql5.5.48]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.48-log Source distribution 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. mysql>
二进制安装:5.6.30
创建用户:
groupadd -r mysql useradd -g mysql -r -s /sbin/nologin -M mysql
创建存储目录:
[[email protected] local]# mkdir /mydata/mysql/data -pv [[email protected] local]# chown -R mysql:mysql /mydata/mysql/ [[email protected] mysql]# mkdir /mydata/mysql/log [[email protected] mysql]# chown -R mysql.mysql /mydata/mysql/log
解压缩:
[[email protected] martin tools]# tar xf mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz -C /usr/local/ [[email protected] martin local]# mv mysql-5.6.30-linux-glibc2.5-x86_64/ mysql-5.6.30
初始化库:
[[email protected] local]# cd /usr/local/ [[email protected] local]# chown -R mysql:mysql mysql-5.6.30/ [[email protected] local]# cd mysql-5.6.30/ [[email protected] mysql-5.6.30]# scripts/mysql_install_db --user=mysql --datadir=/mydata/mysql/data [[email protected] mysql-5.6.30]# cd .. [[email protected] local]# chown -R root.root mysql-5.6.30/
复制配置文件:
[[email protected] support-files]# cd /usr/local/mysql-5.6.30/support-files [[email protected] support-files]# cp my-default.cnf /etc/my.cnf
配置文件:
basedir = /usr/local/mysql datadir = /mydata/mysql/data port = 3306 server_id = 1 socket = /tmp/mysql.sock log-bin=/mydata/mysql/log/master-bin binlog_format=mixed innodb_file_per_table=ON
启动脚本:
[[email protected] local]# ln -sv mysql-5.6.30/ mysql [[email protected] mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld [[email protected] mysql]# chmod +x /etc/rc.d/init.d/mysqld [[email protected] mysql]# chkconfig --add mysqld [[email protected] mysql]# chkconfig mysqld on
导入环境变量:
[[email protected] local]# vim /etc/profile.d/mysqld.sh export PATH=/usr/local/mysql/bin:$PATH [[email protected] local]# . /etc/profile.d/mysqld.sh
mysql数据初始化
mysql> use mysql; mysql> select user,host,password from user; +------+-----------+----------+ | user | host | password | +------+-----------+----------+ | root | localhost | | | root | martin | | | root | 127.0.0.1 | | | root | ::1 | | | | localhost | | | | martin | | +------+-----------+----------+
删除无用账号,设置密码
mysql> DROP USER ‘‘@localhost; mysql> DROP USER ‘root‘@‘::1‘; mysql> DROP USER ‘‘@‘martin‘; mysql> set password for ‘root‘@‘localhost‘=password(‘123456‘); mysql> set password for ‘root‘@‘127.0.0.1‘=password(‘123456‘); mysql> set password for ‘root‘@‘martin‘=password(‘123456‘); mysql> FLUSH PRIVILEGES;
mysql> select user,host,password from user; +------+-----------+-------------------------------------------+ | user | host | password | +------+-----------+-------------------------------------------+ | root | localhost | *437F1809645E0A92DAB553503D2FE21DB91270FD | | root | 127.0.0.1 | *437F1809645E0A92DAB553503D2FE21DB91270FD | | root | marvin | *437F1809645E0A92DAB553503D2FE21DB91270FD | +------+-----------+-------------------------------------------+
用户连接:
[[email protected] mysql5.5.48]# mysql -uroot -hlocalhost --protocol=socket --socket=/tmp/mysql.sock --port=3306 -p
mysql命令解释:
mysql -u, --user 用户名 -h, --host 主机 -p, --password 密码 --protocol={tcp|socket|memory|pipe} 协议 --port 端口 --socket 例如:/tmp/mysql.sock mysql监听的端口: 3306/tcp
查看服务器变量:
mysql> SHOW [{GLOBAL|SESSION}] VARIABLES [LIKE ‘‘];
修改变量:
mysql> SET {GLOBAL|SESSION} VARIABLE_NAME=‘VALUE‘;
注意:无论是全局还是会话级别的动态变量修改,在重启mysqld后都会失效;想永久有效,可定义在配置文件中的相应段中[mysqld];
mysql的快捷键:
Ctrl + w: 删除光标之前的单词 Ctrl + u: 删除光标之前至命令行首的所有内容 Ctrl + y: 粘贴使用Ctrl+w或Ctrl+u删除的内容 Ctrl + a: 移动光标至行首 Ctrl + e: 移动光标至行尾
权限设置
GRANT priv_type [(column_list)] [, priv_type [(column_list)]] ... ON [TABLE|FUNCTION|PROCEDURE] priv_level TO [email protected] [IDENTIFIED BY ‘password‘], [[email protected] [],...] [REQUIRE SSL] [WITH with_option ...]
累加式: mysql> GRANT CREATE ON testdb.* TO ‘marco3‘@‘192.168.1.%‘; mysql> GRANT insert ON testdb.* TO ‘marco3‘@‘192.168.1.%‘;
收回权限:
REVOKE priv_type [(column_list)] [, priv_type [(column_list)]] ... ON [object_type] priv_level FROM user [, user] ... REVOKE ALL PRIVILEGES, GRANT OPTION FROM user [, user] ...
mysql> REVOKE insert ON testdb.* FROM ‘marco3‘@‘192.168.1.%‘;
小结:一般会用到 (grant|revoke) 操作 on [库名.表名] from ‘user‘@‘host‘;
以上是关于mysql之source编译,二进制安装以及权限分配等的主要内容,如果未能解决你的问题,请参考以下文章