MySQL安装配置,命令,异常纪要
Posted pattywgm
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL安装配置,命令,异常纪要相关的知识,希望对你有一定的参考价值。
一、Mac上的安装配置
// brew安装
brew install mysql
// 设置为开机启动
brew services start mysql
// 也可以手动自启
mysql.server start
// 登录
mysql -uroot
注意:
1)若登录时提示没有mysql这个命令,则需要将mysql的bin目录加入PATH:
export PATH=$PATH:/usr/local/mysql/bin
2)此时登录为默认状态,未设密码,若要设置密码,可在登录后运行如下命令:
SET PASSWORD FOR ‘root‘@‘localhost‘ = PASSWORD(‘your password‘);
二、Linux CentOS安装
在centos7上安装mysql5.6,采用source形式安装,过程如下:
1)安装依赖包:yum install -y gcc gcc-c++ kernel-devel ncurses-devel bison cmake
2)命令执行过程:
# Preconfiguration setup
shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
# Beginning of source-build specific instructions
shell> tar zxvf mysql-VERSION.tar.gz
shell> cd mysql-VERSION
shell> mkdir build
shell> cd build
shell> cmake ..
shell> make
shell> make install
# End of source-build specific instructions
# Postinstallation setup
shell> cd /usr/local/mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql (这一步可能引发问题1)
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server
3)环境变量配置
export PATH=$PATH:/usr/local/mysql/bin/
4)设置root用户密码
a、查看当前的用户及登录密码: SELECT User, Host, Password FROM mysql.user;
b、重置密码:
UPDATE mysql.user SET Password = PASSWORD(‘123456‘) where user=‘root‘;
FLUSH PRIVILEGES; // 刷新用户权限信息
c、退出重新登录: mysql -uroot -p
5)允许任何主机远程访问数据库
GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘123456‘ WITH GRANT OPTION;
三、异常问题及解决办法
1、重新启动报错
=> 在my.cnf配置文件中[mysql]下加上tmpdir= /User/userName/mysql/data,或者删除/usr/local/mysql/data目录下logfile*文件
以下问题主要出现在CentOS7环境下的安装过程中:
2、FATAL ERROR: please install the following Perl modules before executing /usr/local/mysql/scripts/mysql_install_db:Data:Dumper
=> yum -y install autoconf
3、mysqld_safe error: log-error set to ‘/var/log/mariadb/mariadb.log‘, however file don‘t exists. Create writable for user ‘mysql‘.
=>
/etc/my.cnf
[mysqld_safe]
log-error=/var/log/mysql/mysql.log
pid-file=/var/run/mysql/mysql.pid
4、Can‘t connect to local MySQL server through socket ‘/tmp/mysql.sock‘
(未解决,可能是之前卸载残留导致,重装了=_=!)
5、Ignoring query to other database
启动mysql时没有带-u参数
6、某个字断被截断,检查插入的数据类型是否与实际表结构中数据类型一致
四、 相关命令
1、查看字符集
SHOW VARIABLES WHERE Variable_name LIKE ‘character\_set\_%‘ OR Variable_name LIKE ‘collation%‘;
show full columns from users; // 产看表字段字符集
2、设置字符集,支持emoji表情符号
utf8mb4 可用于表情符号, 此时应设置数据库、表、表相关字段的字符集均为utf8mb4,方可实现数据的正常插入或是更新
set character_set_results=‘utf8mb4‘;
// 设置表字段字符集
alter TABLE articles MODIFY column title text CHARACTER set utf8mb4;
// 设置表字符集
ALTER TABLE articles CHARSET=utf8mb4;
ALTER TABLE T_CPDAILY_EMOTIONCOMMUNICATES CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
3、字符串常用操作
1)替换 replace
UPDATE articles SET contUrl=REPLACE(contUrl, ‘/we‘, ‘/you‘), sImgUrl=REPLACE(sImgUrl, ‘/root/asse‘, ‘‘),
resUrl=REPLACE(resUrl, ‘/root/asse‘, ‘‘);
2)切割 split
// 设置split函数,返回指定子串长度
CREATE FUNCTION substrCount(x varchar(500), delim varchar(12)) returns int
return (length(x)-length(REPLACE(x, delim, ‘‘)))/length(delim);
select DISTINCT BM, BMFULL from v_ssxx_jrxy ORDER BY BM, substrCount(BMFULL,‘/‘) desc;
3)substring_index内置函数,选择二级部门
SELECT DISTINCT BM, SUBSTRING_INDEX(BMFULL,‘/‘,-1) as secondDepart from v_ssxx_jrxy ORDER BY BM
4、数据迁移
若输入mysqldump提示没有该命令,则启用命令:export PATH=$PATH:/usr/local/mysql/bin/mysqldump
导出整个数据库的表结构及数据:shell中运行>>> mysqldump -uuser -ppassword databaseName -h host > DB.sql
导入:mysqlClient中运行>>> source DB.sql
5、全文索引
innodb要求mysql 5.6.4以上版本支持
1)创建索引,可以在创建表时进行,也可以修改表或直接建立索引的方式
ALTER TABLE ARTICLES ADD COLUMN SEG_CONTENT VARCHAR(4000) DEFAULT NULL;
CREATE FULLTEXT INDEX IDX_SEG_CONTENT ON ARTICLES(SEG_CONTENT);
// 查询
SELECT * FROM ARTICLES WHERE MATCH(SEG_CONTENT) AGAINST(‘新鲜事’ IN BOOLEAN MODE);
MySQL目前支持全文搜索的还有:
NATURAL LANGUAGE MODEL: MyISAM引擎下,该模式对于词频超过50%的词视作停用词
2)操作过程中,可能会发现,对于中文经常会搜索不到结果,原因是,默认配置下innodb_ft_min_token_size的值为3,该值是针对英文
全文搜索的默认设置,用于过滤类似”a”,”to”这类停用词,对于中文,我们需要将该值设置为1 或者 2,否则大部分词长小于3的都将被过滤掉。
重启server设置token_size值为1: /etc/init.d/mysql.server restart --innodb_ft_min_token_size=1
SHOW VARIABLES LIKE ‘innodb_ft_min_token_size‘
删除原有的FullText Index:DROP INDEX IDX_FULL_TEXT_CONTENT ON ARTICLES;
重建全文索引:CREATE FULLTEXT INDEX IDX_CONTENT ON ARTICLES(content);
3) 设置本地停用词表
CREATE TABLE T_CPDAILY_STOPWORDS(value VARCHAR(30)) ENGINE = INNODB;
SET GLOBAL innodb_ft_server_stopword_table = ‘cpdaily/T_CPDAILY_STOPWORDS‘;
4)设置配置项
show VARIABLES like ‘innodb_%‘;
set GLOBAL innodb_optimize_fulltext_only=ON;
set global innodb_ft_aux_table = ‘cpdb/articles‘;
OPTIMIZE TABLE articles;
五、卸载
Mac上的卸载
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
vim /etc/hostconfig (and removed the line MYSQLCOM=-YES-)
rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /var/db/receipts/com.mysql.*
Linux上的卸载
1)
yum list installed mysql*
rpm -qa | grep -i mysql
2)
yum remove mysql mysql-devel mysql-server mysql-libs compat-mysql51
rpm -aq | grep -i mysql
3)
rm -rf /var/lib/mysql
4)
whereis mysql
rm -rf /usr/lib64/mysql
rm -rf /usr/local/mysql
rm -rf /usr/local/mysql/bin/mysql
5)
find / -name mysql
rm -rf /usr/lib/mysql
rm -rf /usr/share/mysql
rm -rf /usr/local/mysql-5.6.35/
rm -rf /run/mysql
rm –rf /usr/my.cnf
rm -rf /root/.mysql_sercret
6)
chkconfig --list | grep -i mysql
chkconfig --del mysqld
rm -rf /var/log/mysql
注!!!
一、安装cmake:
// 获取安装包并解压缩
wget https://cmake.org/files/v3.3/cmake-3.3.2.tar.gz
tar xzvf cmake-3.3.2.tar.gz
// 进入到cmake文件夹中执行引导命令
cd cmake-3.3.2
./bootstrap
// 执行make
gmake
// 执行安装(root权限)
make install
二、安装boost
wget https://sourceforge.Net/projects/boost/files/boost/1.62.0/boost_1_62_0.tar.gz
tar -zxvf boost_1_62_0.tar.gz
cp -r boost_1_62_0 /usr/local/boost
以上是关于MySQL安装配置,命令,异常纪要的主要内容,如果未能解决你的问题,请参考以下文章