mysql学习之旅
1,mysql安装脚本
#!/bin/bash
RSYNC='10.39.2.120::wenhui/database/install'
CMAKE='cmake-2.8.6.tar.gz'
MYSQL='mysql-5.5.24.tar.gz'
MYSQL_DIR='/usr/local/mysql55'
MYSQL_DATADIR='/data1/mysqldata/mysql3306' function main(){
user=`whoami`
if [ "$user" != "root" ]; then
echo "please use root to execute this script"
exit
fi module=$
module_type=$
case "$1" in
cmake)
install_cmake
;;
mysql)
install_mysql $module_type
;;
*)
echo "USAGE: $0 MODULE[cmake|mysql] MODULE_TYPE[full|libmysql|mysqlclient]"
esac
} #install cmake
function install_cmake(){
echo "begin install cmake"; sleep
echo "get tar from $RSYNC"
eval "rsync -avzP $RSYNC/$CMAKE ./"
dir=`echo $CMAKE | perl -pe 's/\Q.tar.gz\E$//g'`
eval "test -e $dir && rm -rf $dir"
eval "tar -zxvf $CMAKE"
echo "cd to $dir"
eval "cd $dir"
./configure
make && make install
cd ..
} #install mysql
function install_mysql(){
LD_PATH='/etc/ld.so.conf.d/mysql.conf'
INSTALL_TYPE='full'
if [ "$1" != "" ]; then
INSTALL_TYPE=$
fi echo "begin install mysql $INSTALL_TYPE"; sleep
echo "get tar from $RSYNC"
eval "rsync -avzP $RSYNC/$MYSQL ./"
dir=`echo $MYSQL | perl -pe 's/\Q.tar.gz\E$//g'`
eval "test -d $dir && rm -rf $dir"
eval "tar -zxvf $MYSQL"
echo "cd to $dir"
eval "cd $dir"
if [ "$INSTALL_TYPE" == "full" ]; then
eval "useradd mysql -s /sbin/nologin"
eval "cmake -DCMAKE_INSTALL_PREFIX=$MYSQL_DIR \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE= \
-DWITH_INNOBASE_STORAGE_ENGINE= \
-DWITH_MEMORY_STORAGE_ENGINE= \
-DWITH_READLINE= \
-DENABLED_LOCAL_INFILE= \
-DMYSQL_DATADIR==$MYSQL_DATADIR \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT= \
-DWITH_PARTITION_STORAGE_ENGINE= \
-DEXTRA_CHARSETS=all \
-DWITH_EXTRA_CHARSETS=all \
"
make && make install #copy configure file
SCRIPT_DIR="$MYSQL_DIR/start"
test -d $SCRIPT_DIR || mkdir -p $SCRIPT_DIR
eval "rsync -avzp $RSYNC/my.cnf $SCRIPT_DIR"
eval "rsync -avzp $RSYNC/init.sh $SCRIPT_DIR" elif [ "$INSTALL_TYPE" == "libmysql" ]; then
eval "cmake -DCMAKE_INSTALL_PREFIX=$MYSQL_DIR \
-DWITHOUT_SERVER=ON
"
make && make install elif [ "$INSTALL_TYPE" == "mysqlclient" ]; then
eval "cmake -DCMAKE_INSTALL_PREFIX=$MYSQL_DIR \
"
make mysqlclient libmysql && make install
fi echo "add bin path to /etc/bashrc"
echo "" >> /etc/bashrc
echo "#mysql envirment" >> /etc/bashrc
echo "export PATH=\$PATH:$MYSQL_DIR/bin" >> /etc/bashrc
echo "add ld path to $LD_PATH"
echo "$MYSQL_DIR/lib" > $LD_PATH
ldconfig
} main $ $
主服务:mysql-server mysql mysql-devel
[root@yz6254 ~]# sh /usr/local/mysql55/start/init.sh 3306 #创建启动脚本
* [root@yz6254 ~]# head install.sh
..............
MYSQL_DIR='/usr/local/mysql55' # 默认数据库安装路径
MYSQL_DATADIR='/data0/mysqldata/mysql3306' # 默认数据库存放路径
...............
* [root@yz6254 ~]# sh install.sh mysql libmysql # 安装libmysqlclient,用于perl,python连mysql数据库使用
==== 安装细节 ======
# cmake
tar zxvf cmake-2.8.6.tar.gz
cd cmake-2.8.6
./configure
make && make install
# Mysql
tar zxvf mysql-5.5.24.tar.gz
cd mysql-5.5.24
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql55 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR==/data0/mysqldata/mysql3306 \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DWITH_EXTRA_CHARSETS=all \
make && make install
数据库默认存放路径:/var/lib/mysql
常见操作:
mysql>
mysql> select version();
#支持日常计算
mysql> select 4*4;
+-----+
| 4*4 |
+-----+
| 16 |
+-----+
1 row in set (0.00 sec)
mysql> select 4+4;
+-----+
| 4+4 |
+-----+
| 8 |
+-----+
1 row in set (0.00 sec)
mysql> select current_date;
+--------------+
| current_date |
+--------------+
| 2015-12-06 |
+--------------+
1 row in set (0.00 sec)
mysql> select version(), current_date;
+-----------+--------------+
| version() | current_date |
+-----------+--------------+
| 5.1.73 | 2015-12-06 |
+-----------+--------------+
1 row in set (0.00 sec)
mysql> create database yongsan_test;
Query OK, 1 row affected (0.00 sec)
mysql> drop database yongsan_test;
Query OK, 0 rows affected (0.40 sec)
注:数据库名称默认不能更改
注:数据库名称默认不能更改 数据库默认存放路径:/var/lib/mysql mysql>
mysql> create table lc_course(
-> id int,
-> course_name varchar(),
-> course_length int,
-> teacher varchar(),
-> category varchar()
-> ); mysql> show tables;
+------------------------+
| Tables_in_yongsan_test |
+------------------------+
| lc_course |
+------------------------+
row in set (0.00 sec) mysql> alter table lc_course rename course
-> ;
Query OK, rows affected (0.00 sec) mysql> show tables;
+------------------------+
| Tables_in_yongsan_test |
+------------------------+
| course |
+------------------------+
row in set (0.00 sec) mysql> alter table course add link varchar();
Query OK, rows affected (0.02 sec)
Records: Duplicates: Warnings: mysql> desc course
-> ;
+---------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+-------+
| id | int() | YES | | NULL | |
| course_name | varchar() | YES | | NULL | |
| course_length | int() | YES | | NULL | |
| teacher | varchar() | YES | | NULL | |
| category | varchar() | YES | | NULL | |
| link | varchar() | YES | | NULL | |
+---------------+--------------+------+-----+---------+-------+
rows in set (0.00 sec) mysql>
mysql> alter table course modify teacher varchar();
Query OK, rows affected (0.03 sec)
Records: Duplicates: Warnings: mysql> desc course;
+---------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+-------+
| id | int() | YES | | NULL | |
| course_name | varchar() | YES | | NULL | |
| course_length | int() | YES | | NULL | |
| teacher | varchar() | YES | | NULL | |
| category | varchar() | YES | | NULL | |
| link | varchar() | YES | | NULL | |
+---------------+--------------+------+-----+---------+-------+
rows in set (0.00 sec) mysql> alter table course change column teacher lecturn varchar();
Query OK, rows affected (0.02 sec)
Records: Duplicates: Warnings:
mysql> desc course;
+---------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+-------+
| id | int() | YES | | NULL | |
| course_name | varchar() | YES | | NULL | |
| course_length | int() | YES | | NULL | |
| lecturn | varchar() | YES | | NULL | |
| category | varchar() | YES | | NULL | |
| link | varchar() | YES | | NULL | |
+---------------+--------------+------+-----+---------+-------+
rows in set (0.00 sec) INSERT INTO course VALUES(,'mysql_linux','','alex','basic','ln'); UPDATE course set course_name='yongsan_123' WHERE id=
经典介绍:
mysql> create user yongsan identified by '123qwe';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> select host,user from user;
+--------------------------------+---------+
| host | user |
+--------------------------------+---------+
| % | root |
| % | yongsan |
| 127.0.0.1 | root |
| localhost | |
| localhost | root |
| localhost | zabbix |
| yz3150.hadoop.data.sina.com.cn | |
| yz3150.hadoop.data.sina.com.cn | root |
+--------------------------------+---------+
8 rows in set (0.00 sec)
mysql> rename user yongsan to yongsan_1;
ERROR (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:
Current database: mysql mysql> set password = password('123qwe');
Query OK, rows affected (0.00 sec) mysql> set password for yongsan_1 = password('123qwe');
Query OK, rows affected (0.00 sec) mysql> select * from course;
+------+-------------+---------------+---------+----------+------+
| id | course_name | course_length | lecturn | category | link |
+------+-------------+---------------+---------+----------+------+
| | mysql_linux | | alex | basic | ln |
| | yongsan_123 | NULL | NULL | fly | NULL |
+------+-------------+---------------+---------+----------+------+
rows in set (0.00 sec) mysql>
mysql>
mysql>
mysql> delete from course where id='';
Query OK, row affected (0.00 sec) mysql> select * from course;
+------+-------------+---------------+---------+----------+------+
| id | course_name | course_length | lecturn | category | link |
+------+-------------+---------------+---------+----------+------+
| | mysql_linux | | alex | basic | ln |
+------+-------------+---------------+---------+----------+------+
row in set (0.00 sec) [yongsan@yz3110 ~]$ mysql -uroot -p yongsan_test < yongsan_test.sql
Enter password: mysql> select * from course;
+------+-------------+---------------+---------+----------+------+
| id | course_name | course_length | lecturn | category | link |
+------+-------------+---------------+---------+----------+------+
| | mysql_linux | | alex | basic | ln |
| | yongsan_123 | NULL | NULL | fly | NULL |
+------+-------------+---------------+---------+----------+------+
rows in set (0.00 sec) mysql> show character set;
+----------+-----------------------------+---------------------+--------+
| Charset | Description | Default collation | Maxlen |
+----------+-----------------------------+---------------------+--------+
| big5 | Big5 Traditional Chinese | big5_chinese_ci | |
| dec8 | DEC West European | dec8_swedish_ci | |
| cp850 | DOS West European | cp850_general_ci | |
| hp8 | HP West European | hp8_english_ci | |
| koi8r | KOI8-R Relcom Russian | koi8r_general_ci | |
| latin1 | cp1252 West European | latin1_swedish_ci | |
| latin2 | ISO - Central European | latin2_general_ci | |
| swe7 | 7bit Swedish | swe7_swedish_ci | |
| ascii | US ASCII | ascii_general_ci | |
| ujis | EUC-JP Japanese | ujis_japanese_ci | |
| sjis | Shift-JIS Japanese | sjis_japanese_ci | |
| hebrew | ISO - Hebrew | hebrew_general_ci | |
| tis620 | TIS620 Thai | tis620_thai_ci | |
| euckr | EUC-KR Korean | euckr_korean_ci | |
| koi8u | KOI8-U Ukrainian | koi8u_general_ci | |
| gb2312 | GB2312 Simplified Chinese | gb2312_chinese_ci | |
| greek | ISO - Greek | greek_general_ci | |
| cp1250 | Windows Central European | cp1250_general_ci | |
| gbk | GBK Simplified Chinese | gbk_chinese_ci | |
| latin5 | ISO - Turkish | latin5_turkish_ci | |
| armscii8 | ARMSCII- Armenian | armscii8_general_ci | |
| utf8 | UTF- Unicode | utf8_general_ci | |
| ucs2 | UCS- Unicode | ucs2_general_ci | |
| cp866 | DOS Russian | cp866_general_ci | |
| keybcs2 | DOS Kamenicky Czech-Slovak | keybcs2_general_ci | |
| macce | Mac Central European | macce_general_ci | |
| macroman | Mac West European | macroman_general_ci | |
| cp852 | DOS Central European | cp852_general_ci | |
| latin7 | ISO - Baltic | latin7_general_ci | |
| cp1251 | Windows Cyrillic | cp1251_general_ci | |
| cp1256 | Windows Arabic | cp1256_general_ci | |
| cp1257 | Windows Baltic | cp1257_general_ci | |
| binary | Binary pseudo charset | binary | |
| geostd8 | GEOSTD8 Georgian | geostd8_general_ci | |
| cp932 | SJIS for Windows Japanese | cp932_japanese_ci | |
| eucjpms | UJIS for Windows Japanese | eucjpms_japanese_ci | |
+----------+-----------------------------+---------------------+--------+
rows in set (0.00 sec) 查看默认字符编码
mysql> show variables like 'collation%';
+----------------------+-------------------+
| Variable_name | Value |
+----------------------+-------------------+
| collation_connection | utf8_general_ci |
| collation_database | latin1_swedish_ci |
| collation_server | latin1_swedish_ci |
+----------------------+-------------------+
rows in set (0.00 sec) mysql> show variables like 'character_set%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
rows in set (0.00 sec) mysql> create database lcdb default character set utf8 default collate utf8_general_ci;
Query OK, row affected (0.00 sec)
指定字符编码
mysql学习之旅的更多相关文章
- MySQL学习
关于MySQL学习,先推荐一个网站,资源很多.讲得很细 StudyMySQL-最好的MySQL学习网站 我的MySQL学习之旅: 1.简单了解下MySQL数据库,安装MySQL.MySQL管理工具(刚 ...
- 180分钟的python学习之旅
最近在很多地方都可以看到Python的身影,尤其在人工智能等科学领域,其丰富的科学计算等方面类库无比强大.很多身边的哥们也提到Python非常的简洁方便,比如用Django搭建一个见得网站只需要半天时 ...
- 开发了5年android,我开始了go学习之旅
前言 做了近5年的android开发,最近项目也是不怎么忙,空闲的时候总会思考一些事情,不过作为移动开发,我个人觉得很有必要学习后台开发,由于公司是Go语言开发的,了解go语言一段时间后,我发现go语 ...
- 我的MYSQL学习心得(一) 简单语法
我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据类型 我的MYSQL学习心得(五) 运 ...
- WCF学习之旅—第三个示例之四(三十)
上接WCF学习之旅—第三个示例之一(二十七) WCF学习之旅—第三个示例之二(二十八) WCF学习之旅—第三个示例之三(二十九) ...
- Hadoop学习之旅二:HDFS
本文基于Hadoop1.X 概述 分布式文件系统主要用来解决如下几个问题: 读写大文件 加速运算 对于某些体积巨大的文件,比如其大小超过了计算机文件系统所能存放的最大限制或者是其大小甚至超过了计算机整 ...
- 我的MYSQL学习心得(二) 数据类型宽度
我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据类型 我的MYSQL学习心得(五) 运 ...
- 我的MYSQL学习心得(三) 查看字段长度
我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(四) 数据类型 我的MYSQL学习心得(五) 运 ...
- 我的MYSQL学习心得(四) 数据类型
我的MYSQL学习心得(四) 数据类型 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(五) 运 ...
随机推荐
- Linux系统——日志文件
日志文件的分类 (1)内核及系统日志 由系统服务rsyslog管理,根据去主配置文件/etc/rsyslog.conf中的设置决定将内核消息及各种系统程序消息记录到什么位置. /etc/rsyslog ...
- Tomcat源码
1.Connector Container:Engine,Host,Context,Wrapper(责任链的设计模式) Valve: Tomcat 中一个最容易发现的设计模式就是责任链模式,这 ...
- GZFramework错误(升级修改)日志
sqlserver下事务中处理出现为初始化selectcommand的connection属性修改CommandDataBase中的PrepareCommand方法
- 架构私用Nuget服务器
1.新建一个空的asp.net站点 2.通过nuget引用 Nuget.Server程序集,引用后项目会多出一些文件.修改web.config 里的apikey为你要上传包时用的apikey,我的为: ...
- 算法+OpenCV】基于opencv的直线和曲线拟合与绘制(最小二乘法)
http://blog.csdn.net/guduruyu/article/details/72866144 最小二乘法多项式曲线拟合,是常见的曲线拟合方法,有着广泛的应用,这里在借鉴最小二乘多项式曲 ...
- linux内核动态打印
参考:https://www.cnblogs.com/pengdonglin137/p/4622460.html https://linux.cn/article-3682-1.html?pr 如何打 ...
- PHP秒杀系统全方位设计分析(一)
秒杀系统特点人多商品少时间短流量高外挂机器[黄牛和非黄牛] 技术分析瞬间高并发的处理能力多层次的分布式处理能力人机交互与对抗[12306验证码图片] 技术选型分析Linux+Nginx+PHP+Mys ...
- XPO开发指南简要
一.XPO简介: XPO即eXpress Persistent Objects for .NET,现在这里介绍的版本是1.5. XPO在应用程序代码和数据库之间扮演了一个中间层的角色,简单而言,就是将 ...
- awk二十问-【AWK学习之旅】
---===AWK学习之旅===--- 一行命令: 1.打印输入每行的字段总数: 最后一行的字段总数:END{print NF} 每行都显示字段总数: {print NF} 2.打印指定行: aw ...
- 在eclipse搭建python开发环境
在一次看别人帖子的时候发现,别人是用eclipse来写python代码的,所以好奇也想尝试一番,之前一直在用Pycharm,这个也确实是最好的开发python的IDE了,但是有时候也会有卡顿的情况,主 ...