此笔记内容所使用的安装包是tar.gz的包,不是rpm和在线安装。版本是mysql5系列的。
1.删除mariadb和mysql
mariadb是mysql的一个分支,但要安装mysql需要删除它
rpm -qa|grep mariadb,查看mariadb情况,有就删除
rpm -e -nodeps mariadb....名字
rpm -qa |grep mysql 查看是否已经有mysql有就删除
rpm -qa|grep mariadb
显示:mariadb-libs-5.5.44-2.el7.centos.x86_64
rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
2.下载mysql安装包
查看自己的linux的版本
uname -a
查多少位系统
getconf LONG_BIT
到官网找对应的版本下载.并传到服务器上。
3.复制jar包、解压
cp mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz /usr/local
tar -xvf mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz
把解压后的文件夹重命名 为mysql。(这是linux下默认的mysql安装目录)
mv mysql-5.6.39-linux-glibc2.12-x86_64 mysql
注意:一定要解压在 usr/local下,并且名为mysql 否则还需要修改配置文件
4.添加用户组和用户
groupadd mysql和useradd -r -g mysql mysql
#给mysql添加密码
passwd mysql
5.修改配置文件
1.复制 cp support-files/my-default.cnf /etc/my.cnf (my.cnf是mysql默认配置文件,没有就自己新建一个my.cnf)
2.编辑 my.cnf 解决乱码问题 vi /etc/my.cnf 加上下面内容
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[mysqld_safe]
log-error =/usr/local/mysql/logs/error.log
[mysqld]
skip-name-resolve
#设置3306端口
port=3306
# 设置mysql的安装目录
basedir=/usr/local/mysql
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/mysql/data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
3.复制mysql.server 到/etc/init.d/ 目录下 【把启动脚本放在初始化目录,可以直接service mysql start 这样启动mysql】
cp mysql.server /etc/init.d/mysql (mysql是服务名)
4.修改/etc/init.d/mysql 参数
输入命令 vi /etc/init.d/mysql
添加两个目录位置
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
5.给目录/usr/local/mysql 更改拥有者
输入命令
chown -R mysql:mysql /usr/local/mysql/
chmod -R 777 /usr/local/mysql/
6.初始化如果出错就手动创建错误信息中的文件
在bin文件夹下执行
./mysqld --initialize --user=mysql #会自动创建配置中的文件夹
可能需要手动创建 /usr/local/mysql/logs/error.log
6.初始化数据库
老版本:
进入mysql下的scripts ,如果你看到mysql_install_db
就输命令
./mysql_install_db --user=mysql --initialize
生成出一个data目录,代表数据库已经初始化成功。
新版本:
输入命令 ./mysqld --initialize --user=mysql --explicit_defaults_for_timestamp
7.启动myql
service mysql start
如遇到错误:
Starting MySQL... ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid).
解决方法 :原因是没有初始化成功,返回完成初始化步骤。
8.把mysql放到默认路径
ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
启动客户端:mysql -uroot -p
9.更改环境变量
vi /etc/profile
export MYSQL_HOME=/usr/local/mysql/
export PATH=\$PATH:$MYSQL_HOME/bin
配置好mysql环境变量后,我们往后登录mysql就不用再去到/usr/local/mysql/bin目录才能登录了,现在可以在任意目录下登录mysql了
10.设置mysql开机自启
执行:
chkconfig --add mysql
chkconfig --level 35 mysql on
chkconfig --list mysql
chmod +x /etc/rc.d/init.d/mysql
1、添加mysql服务
输入命令 chkconfig --add mysql 【mysqld -install】
2、设置mysql服务为自动
输入命令 chkconfig mysql on
11.无密码启动mysql
重置MySQL中root用户密码及验证
service mysql stop
killall -TERM mysqld
mysqld_safe --skip-grant-tables &
进入mysql后运行
UPDATE user SET authentication_string=PASSWORD('your pass') where USER='root';
FLUSH PRIVILEGES;
退出,启动Mysql 服务
正常登录进入mysql后
还需 执行
SET PASSWORD = PASSWORD('your pass');
才能正常执行所有语句。
12.设置远程登录
方式一
GRANT ALL PRIVILEGES ON *.* TO'your username'@'%' IDENTIFIED BY 'your password' WITH GRANT OPTION;
方式二
update user set host='%' where user='root';
可以创建新用户
create user 'xxx'@'%' identified by '123';
查看用户列表 localhost只有本地能访问, %可以远程访问。
select host,user from user;
FLUSH PRIVILEGES;
13.关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
14.附录:linux错误代码
errno.00 is: Success 成功
errno.01 is: Operation not permitted 不允许此类操作
errno.02 is: No such file or directory 没有此文件或目录
errno.03 is: No such process 没有此进程
errno.04 is: Interrupted system call 中断系统调用
errno.05 is: Input/output error 输入输出错误
errno.06 is: No such device or address 没有此设备或地址
errno.07 is: Argument list too long 参数过长
errno.08 is: Exec format error 执行格式错误
errno.09 is: Bad file descriptor 无效的文件描述符
errno.10 is: No child processes 不存在子进程
errno.11 is: Resource temporarily unavailable 资源暂时不可用
errno.12 is: Cannot allocate memory 分配内存失败
errno.13 is: Permission denied 权限错误
errno.14 is: Bad address 地址错误
errno.15 is: Block device required 块设备请求
errno.16 is: Device or resource busy 设备或资源忙
errno.17 is: File exists 文件已经存在
errno.18 is: Invalid cross-device link 无效的交叉连接设备
errno.19 is: No such device 没有此设备
errno.20 is: Not a directory 不是一个目录
errno.21 is: Is a directory 是一个目录
errno.22 is: Invalid argument 参数非法
errno.23 is: Too many open files in system 系统打开文件太多
errno.24 is: Too many open files 打开文件太多
errno.25 is: Inappropriate ioctl for device 设备部支持该操作
errno.26 is: Text file busy 文本文件忙
errno.27 is: File too large 文件太大
errno.28 is: No space left on device 设备没有空间,一般为存储设备
errno.29 is: Illegal seek 非法的seek操作
errno.30 is: Read-only file system 只读文件系统
errno.31 is: Too many links 太多连接
errno.32 is: Broken pipe 管道破裂
errno.33 is: Numerical argument out of domain 数值参数超出取值范围
errno.34 is: Numerical result out of range 数值结果超出取值范围
errno.35 is: Resource deadlock avoided 资源死锁
errno.36 is: File name too long 文件名太长
errno.37 is: No locks available 没有可用的锁
errno.38 is: Function not implemented 函数没有执行
errno.39 is: Directory not empty 目录非空
errno.40 is: Too many levels of symbolic links 太多级符号连接
errno.41 is: Unknown error 41 41未知错误
errno.42 is: No message of desired type 不被接受的消息类型
errno.43 is: Identifier removed 标识符已被删除
errno.44 is: Channel number out of range 。。。
errno.45 is: Level 2 not synchronized
errno.46 is: Level 3 halted
errno.47 is: Level 3 reset
errno.48 is: Link number out of range
errno.49 is: Protocol driver not attached
errno.50 is: No CSI structure available
errno.51 is: Level 2 halted
errno.52 is: Invalid exchange
errno.53 is: Invalid request descriptor
errno.54 is: Exchange full
errno.55 is: No anode
errno.56 is: Invalid request code
errno.57 is: Invalid slot
errno.58 is: Unknown error 58
errno.59 is: Bad font file format
errno.60 is: Device not a stream
errno.61 is: No data available
errno.62 is: Timer expired
errno.63 is: Out of streams resources
errno.64 is: Machine is not on the network
errno.65 is: Package not installed
errno.66 is: Object is remote
errno.67 is: Link has been severed
errno.68 is: Advertise error
errno.69 is: Srmount error
errno.70 is: Communication error on send
errno.71 is: Protocol error
errno.72 is: Multihop attempted
errno.73 is: RFS specific error
errno.74 is: Bad message
errno.75 is: Value too large for defined data type
errno.76 is: Name not unique on network
errno.77 is: File descriptor in bad state
errno.78 is: Remote address changed
errno.79 is: Can not access a needed shared library
errno.80 is: Accessing a corrupted shared library
errno.81 is: .lib secion in a.out corrupted
errno.82 is: Attempting to link in too many shared libraries
errno.83 is: Cannot exec a shared library directly
errno.84 is: Invalid or incomplete multibyte or wide character
errno.85 is: Interrupted system call should be restarted
errno.86 is: Streams pipe error
errno.87 is: Too many users
errno.88 is: Socket operation on non-socket
errno.89 is: Destination address required
errno.90 is: Message too long
errno.91 is: Protocol wrong type for socket
errno.92 is: Protocol not available
errno.93 is: Protocol not supported
errno.94 is: Socket type not supported
errno.95 is: Operation not supported
errno.96 is: Protocol family not supported
errno.97 is: Address family not supported by protocol
errno.98 is: Address already in use
errno.99 is: Cannot assign requested address
errno.100 is: Network is down
errno.101 is: Network is unreachable
errno.102 is: Network dropped connection on reset
errno.103 is: Software caused connection abort
errno.104 is: Connection reset by peer
errno.105 is: No buffer space available
errno.106 is: Transport endpoint is already connected
errno.107 is: Transport endpoint is not connected
errno.108 is: Cannot send after transport endpoint shutdown
errno.109 is: Too many references: cannot splice
errno.110 is: Connection timed out
errno.111 is: Connection refused
errno.112 is: Host is down
errno.113 is: No route to host
errno.114 is: Operation already in progress
errno.115 is: Operation now in progress
errno.116 is: Stale NFS file handle
errno.117 is: Structure needs cleaning
errno.118 is: Not a XENIX named type file
errno.119 is: No XENIX semaphores available
errno.120 is: Is a named type file
errno.121 is: Remote I/O error
errno.122 is: Disk quota exceeded
errno.123 is: No medium found
errno.124 is: Wrong medium type
errno.125 is: Operation canceled
errno.126 is: Required key not available
errno.127 is: Key has expired
errno.128 is: Key has been revoked
errno.129 is: Key was rejected by service
errno.130 is: Owner died
errno.131 is: State not recoverable
errno.132 is: Unknown error 132
132-255全是Unknown error