linux安装mysql

软件提取

资料:取码: 525u

网速镜像wget下载慢时候,或内网安装时,可开先下载文件直接安装。

安装编译工具及库文件

yum -y install gcc gcc-c++ make autoconf libtool-ltdl-devel gd-devel freetype-devel libxml2-devel libjpeg-devel libpng-devel openssl-devel curl-devel bison patch unzip libmcrypt-devel libmhash-devel ncurses-devel sudo bzip2 flex libaio-devel

安装cmake编译器

  • 进入/usr目录 (我安装的文件放在/usr目录下,目录随意)
cd /usr
  • 下载cmake安装包
wget http://www.cmake.org/files/v3.1/cmake-3.1.1.tar.gz
  • 解压安装包并进入安装目录
tar zxvf cmake-3.1.1.tar.gz
cd cmake-3.1.1
  • 编译安装
./bootstrap
make && make install

安装boost

  • 在/usr/local下创建boost文件夹
mkdir -p /usr/local/boost
  • 进入boost文件夹
cd /usr/local/boost
  • 在这个文件夹下载 boost
 wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
  • 解压boost
tar -xvzf boost_1_59_0.tar.gz

安装mysql

  • 进入/usr目录
cd /usr
  • 下载mysql并解压mysql
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.15.tar.gz
tar zxvf mysql-5.6.15.tar.gz
  • 进入mysql解压
cd mysql-5.6.15
  • mysql的cmake配置文件添加
-DWITH_BOOST=/usr/local/boost
  • 编译安装mysql
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/webserver/mysql/ -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_INNODB_MEMCACHED=1 -DWITH_DEBUG=OFF -DWITH_ZLIB=bundled -DENABLED_LOCAL_INFILE=1 -DENABLED_PROFILING=ON -DWITH_BOOST=/usr/local/boost -DMYSQL_MAINTAINER_MODE=OFF -DMYSQL_DATADIR=/usr/local/webserver/mysql/data -DMYSQL_TCP_PORT=3306
  • make
make && make install
  • 查看mysql版本
    如果可以查看到,则mysql安装正确
/usr/local/webserver/mysql/bin/mysql --version
  • 报错问题解决

1 CMake安装mysql时报错

CMake Error at cmake/readline.cmake:85 (MESSAGE):
Curses library not found. Please install appropriate package,

解决

yum -y install ncurses-devel
rm -rf CMakeCache.txt

mysql配置

  • 创建mysql运行使用的用户mysql
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
  • 创建binlog和库的存储路径并赋予mysql用户权限
mkdir -p /usr/local/webserver/mysql/binlog /www/data_mysql
chown mysql.mysql /usr/local/webserver/mysql/binlog/ /www/data_mysql/
  • 将mysql文件夹的权限给mysql用户
chown -R mysql /usr/local/webserver/mysql
chgrp -R mysql /usr/local/webserver/mysql
  • 创建my.cnf配置文件
vim /etc/my.cnf
  • my.cnf文件里内容如下
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
lower_case_table_names =1
replicate-ignore-db = mysql
replicate-ignore-db = test
replicate-ignore-db = information_schema
user = mysql
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/webserver/mysql
datadir = /www/data_mysql
log-error = /usr/local/webserver/mysql/mysql_error.log
pid-file = /usr/local/webserver/mysql/mysql.pid
open_files_limit = 65535
back_log = 600
max_connections = 5000
max_connect_errors = 1000
table_open_cache = 1024
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 600#thread_concurrency = 8
query_cache_size = 128M
query_cache_limit = 2M
query_cache_min_res_unit = 2kdefault-storage-engine = MyISAMdefault-tmp-storage-engine=MYISAM
thread_stack = 192K
transaction_isolation = READ-COMMITTED
tmp_table_size = 128M
max_heap_table_size = 128M
log-slave-updates
log-bin = /usr/local/webserver/mysql/binlog/binlog
binlog-do-db=oa_fb
binlog-ignore-db=mysql
binlog_cache_size = 4M
binlog_format = MIXED
max_binlog_cache_size = 8M
max_binlog_size = 1G
relay-log-index = /usr/local/webserver/mysql/relaylog/relaylog
relay-log-info-file = /usr/local/webserver/mysql/relaylog/relaylog
relay-log = /usr/local/webserver/mysql/relaylog/relaylog
expire_logs_days = 10
key_buffer_size = 256M
read_buffer_size = 1M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
interactive_timeout = 120
wait_timeout = 120
skip-name-resolve
slave-skip-errors = 1032,1062,126,1114,1146,1048,1396#master-host = 192.168.1.2#master-user = username#master-password = password#master-port = 3306
server-id = 1
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

slow_query_log_file=/usr/local/webserver/mysql/mysql_slow.log
long_query_time = 1
[mysqldump]
quick
max_allowed_packet = 32M
  • 初始化数据库
cd   /usr/local/webserver/mysql/
执行
/usr/local/webserver/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf  --user=mysql
  • 创建开机启动脚本
cd /usr/local/webserver/mysql/
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 35 mysqld on
  • 启动mysql
service mysqld start
  • 连接mysql
/usr/local/webserver/mysql/bin/mysql -u root -p

如果看到如果下,,则成功

mysql>
看一下数据库
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| demo1              |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.00 sec)

mysql>
ok~~~~~~
  • 修改mysql密码
    进入mysql命令行
格式:SET PASSWORD FOR '用户名'@'主机' = PASSWORD(‘密码');
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('root');

创建用户并授权

grant all privileges on *.* to 用户名@'%' identified by '密码' with grant option;
grant all privileges on *.* to root@'%' identified by 'root' with grant option;

测试mysql用户名和密码修改是否生效

连接mysql
会要输入密码,输入刚才设置的密码(root),如果能连接mysql,说明设置成功

同一个局域网连接mysql

用navicat连接连接mysql
备注:
连接名:随便起
主机名或ip地址:虚拟机的ip地址
Linux命令行获取:ip addr
端口号:mysql的端口号 3306
用户名:root
密码:root
连接测试,

不出意外会失败,原因

1)Linux的防火墙没有关闭
关闭防火墙
systemctl stop firewalld,systemctl disable firewalld
2) 服务器上登录mysql,查看是否有地址限制,
语法:
use mysql;
select host,user from user;
grant all privileges on *.* to 'root'@'%' identified by '密码';
flush privileges;

操作如下:
mysql> select host,user from user ;
mysql> grant all privileges on *.* to 'root'@'%' identified by 'root';
mysql> flush privileges;

全部操作及显示:
mysql> use mysql ;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select host,user from user ;
+-----------------------+------+
| host                  | user |
+-----------------------+------+
| %                     | root |
| 127.0.0.1             | root |
| ::1                   | root |
| localhost             |      |
| localhost             | root |
| localhost.localdomain |      |
| localhost.localdomain | root |
+-----------------------+------+
7 rows in set (0.02 sec)

mysql> grant all privileges on *.* to 'root'@'%' identified by 'root';
Query OK, 0 rows affected (0.07 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.34 sec)


同一个局域网连接测试:
连接成功
现在开始开心的使用mysql吧~~~~~~

image

参考

http://www.runoob.com/linux/mysql-install-setup.html

独在异乡为异客,每逢佳节倍思亲。
posted @ 2021-04-06 00:27  安财迁客  阅读(62)  评论(0编辑  收藏  举报