1 linux环境 mysql安装运行
1.1下载
案例 在/usr/local/src,下载msql
wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.14-1.el7.x86_64.rpm-bundle.tar
1.2 安装
在/usr/local/src创建mysql-install.sh,并运行
#!/bin/bash
mkdir /usr/local/mysql
tar -xvf mysql-5.7.14-1.el7.x86_64.rpm-bundle.tar -C /usr/local/mysql
cd /usr/local/mysql && yum remove mysql-libs -y
rpm -ivh mysql-community-common-5.7.14-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.14-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.14-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.14-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-5.7.14-1.el7.x86_64.rpm
#cd ../
#cp binary_log_types.h /usr/include/mysql/
# 删除mysql目录
rm -rf /usr/local/mysql
1.3常见异常
原因: 缺少libaio库
解决
wget http://mirror.centos.org/centos/6/os/x86_64/Packages/libaio-0.3.107-10.el6.x86_64.rpm
rpm -ivh libaio-0.3.107-10.el6.x86_64.rpm
1.4再次运行
sh mysql-install.sh
1.5启动/停止服务
启动服务:service mysqld start
重启服务:service mysqld restart
停止服务:service mysqld stop
1.6登入mysql
mysql -uroot -p
首次登入没有密码,会在 /var/log/mysqld.log 自动生成密码
grep "password" /var/log/mysqld.log
第一次登入必须修改密码:
密码不能过于简单
mysql> SET PASSWORD = PASSWORD('T123456');
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> SET PASSWORD = PASSWORD('Test_123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
2. 配置文件简介
/etc/my.cnf :mysql的配置文件
[mysqld]
# innodb_buffer_pool_size = 128M
# log_bin
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql #数据库文件存放路径
socket=/var/lib/mysql/mysql.sock #客户程序与服务器之间的本地通信指定一个套接字文件
symbolic-links=0
log-error=/var/log/mysqld.log #日志存放路径
pid-file=/var/run/mysqld/mysqld.pid #pid存放路径
3. 字符集设置
3.1查看字符编码
mysql> show variables like '%char%';
+--------------------------------------+----------------------------+
| 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/ |
| validate_password_special_char_count | 1 |
+--------------------------------------+----------------------------+
9 rows in set (0.01 sec)
数据库如果字符编码是 latin1,存储中文,会有乱码出现
3.2修改字符编码
在/etc/my.cnf 最后面添加如下内容
# vi /etc/my.cnf
# 需添加的内容
[mysqld]
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
修改后重启mysql服务
注意:
以后创建的库和表的字符编码默认是utf-8,但是以前创建的库和表的字符编码没有修改,如果需要修改,则写sql去修改
例如
alter database test1 default character set utf8;
alter table t1 convert to character set utf8 collate utf8_general_ci;
alter table t1 default character set utf8;
4. 远程连接mysql
4.1创建用户,授权
mysql> grant all privileges on *.* to 'root'@'%' identified by 'Test_123456';
Query OK, 0 rows affected, 1 warning (0.02 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
说明:
all privileges : 所有的权限
*.* :表示master所有的表,都可以主从复制
mysync:创建授权用户名
% :表示所有的客户端,这样不安全,一般指定ip,更安全
Test_123456:创建授权用户名密码
4.2远程连接
如果连不上,查看ip是否能ping通
查看端口是否开放