Mysql手动安装
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mysql手动安装相关的知识,希望对你有一定的参考价值。
以下内容是我安装的实际操作命令。
一、准备
///备份、下载源
# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyuncs.com/repo/Centos-6.repo
# yum -y install lrzsz cmake///安装环境
# wget http://invisible-island.net/datafiles/release/ncurses.tar.gz
# tar -zxvf ncurses.tar.gz
# cd ncurses-5.9
# ./configure
# make && make install
///mysql 直接使用lnmp包里5.6版本。
///lnmp下载地址http://lnmp.org/download.html,推荐使用国内镜像下载
#cd ..
# tar -zxvf mysql-5.6.23.tar.gz///解压mysql
# cd mysql-5.6.23
MYSQL说明:
路径:/usr/local/mysql
数据库路径:/usr/local/mysql/var
///编译
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1
///安装
# make && make install
///创建组 & 账户
# groupadd mysql
# useradd -s /sbin/nologin -M -g mysql mysql
///赋予 /usr/local/mysql/ 权限
# chown -R mysql:mysql /usr/local/mysql/
如果之前编译过mysql报错,在次编译前到mysql目录下删除/mysql5623/CMakeCache.txt
# rm -rf CMakeCache.txt
///创建数据存储 & 赋权限
# mkdir -p /usr/local/mysql/var
# chown -R mysql:mysql /usr/local/mysql/var
///写入配置文件(灰色部分)。如果,到最后EOF没有返回到命令行,手动输入回车即可
中间略
# cat > /etc/my.cnf<<EOF
[client]
#password = you password
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
datadir = /usr/local/mysql/var
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
thread_cache_size = 8
query_cache_size = 8M
tmp_table_size = 16M
table_open_cache = 64
explicit_defaults_for_timestamp = true
#skip-networking
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535
log-bin=mysql-bin
binlog_format=mixed
server-id = 1
expire_logs_days = 10
#loose-innodb-trx=0
#loose-innodb-locks=0
#loose-innodb-lock-waits=0
#loose-innodb-cmp=0
#loose-innodb-cmp-per-index=0
#loose-innodb-cmp-per-index-reset=0
#loose-innodb-cmp-reset=0
#loose-innodb-cmpmem=0
#loose-innodb-cmpmem-reset=0
#loose-innodb-buffer-page=0
#loose-innodb-buffer-page-lru=0
#loose-innodb-buffer-pool-stats=0
#loose-innodb-metrics=0
#loose-innodb-ft-default-stopword=0
#loose-innodb-ft-inserted=0
#loose-innodb-ft-deleted=0
#loose-innodb-ft-being-deleted=0
#loose-innodb-ft-config=0
#loose-innodb-ft-index-cache=0
#loose-innodb-ft-index-table=0
#loose-innodb-sys-tables=0
#loose-innodb-sys-tablestats=0
#loose-innodb-sys-indexes=0
#loose-innodb-sys-columns=0
#loose-innodb-sys-fields=0
#loose-innodb-sys-foreign=0
#loose-innodb-sys-foreign-cols=0
default_storage_engine = InnoDB
#innodb_data_home_dir = /usr/local/mysql/var
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /usr/local/mysql/var
#innodb_buffer_pool_size = 16M
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
EOF
///安装数据
# /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var --user=mysql
# chgrp -R mysql /usr/local/mysql/. ///注意语句后有个”点”
///开机启动
# \cp support-files/mysql.server /etc/init.d/mysql
# chmod 755 /etc/init.d/mysql
///信息写入配置,如果,到最后EOF没有返回到命令行,手动输入回车即可
# cat > /etc/ld.so.conf.d/mysql.conf<<EOF
/usr/local/mysql/lib
/usr/local/lib
EOF
///共享动态链接库
# ldconfig
# ln -sf /usr/local/mysql/lib/mysql /usr/lib/mysql
# ln -sf /usr/local/mysql/include/mysql /usr/include/mysql
///系统识别命令
# ln -s /usr/local/mysql/bin/mysql /usr/bin
二、启动& 重启&停止
# /etc/init.d/mysql start
# /etc/init.d/mysql restart
# /etc/init.d/mysql stop
查看端口是否启动成功
# netstat -an | grep 3306
效果图:
三、账号、密码
初始数据库,用户名:root 密码:‘空’,显示Enter password直接回车
# mysql -uroot -p
修改用户密码:
///***部分为你实际用户名&密码
///注意下面命令要登录mysql里执行
mysql > update mysql.user set password=PASSWORD(‘your passwore‘) where user=‘your user‘;
/// 示例
mysql > update mysql.user set password=PASSWORD(‘122198‘) where user=‘root‘;
///刷新权限表,输入如下命令
mysql > flush privileges;
四、远程连接MySql
如果需要远程连接数据库,需要授权账号远程登录。本地登录mysql
mysql > GRANT ALL PRIVILEGES ON *.* TO ‘myuser‘@‘%‘ IDENTIFIED BY ‘mypassword‘ WITH GRANT OPTION;
*.* ///代表所有数据库都可以远程访问或者直接指定,
如zabbix.*,代表只有zabbix数据库可以远程访问
myuser ///远程访问的账号
% ///允许所有IP连接,或直接指定要访问的IP
mysql > FLUSH PRIVILEGES;///更新数据
五、-结束
参考:lnmp一键安装包mysql.sh教程,感谢lnmp作者。
本文出自 “悟透的杂货铺” 博客,请务必保留此出处http://wutou.blog.51cto.com/615096/1738593
以上是关于Mysql手动安装的主要内容,如果未能解决你的问题,请参考以下文章