rpm -qa|grep -i mysql
如果显示有如下包则说明已安装mysql
mysql-4.1.12-3.RHEL4.1
mysqlclient10-3.23.58-4.RHEL4.1
如果已安装,则需要删除已安装的数据库,使用以下命令来删除数据库
删除命令:rpm -e --nodeps 包名
( rpm -ev mysql-4.1.12-3.RHEL4.1 )
删除老版本mysql的开发头文件和库
命令:rm -fr /usr/lib/mysql
rm -fr /usr/include/mysql
注意:卸载后/var/lib/mysql中的数据及/etc/my.cnf不会删除,如果确定没用后就手工删除
rm -f /etc/my.cnf
rm -fr /var/lib/mysql
下载mysql的rpm包
可以通过wget下载具体的地址因为不能用链接请大家去官网去找
(1)MySQL-server-5.6.10-1.rhel5.x86_64.rpm:MySQL服务器;
(2)MySQL-client-5.6.10-1.rhel5.x86_64.rpm:MySQL客户端;
(3)MySQL-devel-5.6.10-1.rhel5.x86_64.rpm:Mysql开发依赖包。
下载后放到Liunx服务器中,如图所示
安装MySQL Server的rpm包
rpm -ivh MySQL-server-5.6.21-1.linux_glibc2.5.x86_64.rpm
安装过程如图所示
安装完成后会生成root用户的随机密码,请使用“cat /root/.mysql_secret”或类似命令进行查看。
安装MySQL客户端
rpm -ivh MySQL-client-5.6.21-1.linux_glibc2.5.x86_64.rpm
安装MySQL开发依赖包
rpm -ivh MySQL-devel-5.6.21-1.linux_glibc2.5.x86_64.rpm
启动msyql
安装完成后mysql是没有启动的,运行mysql命令会提示如下错误:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
可使用如下命令启动MySQL:
service mysql start
或者使用如下命令:
/etc/init.d/mysql start
可使用SET PASSWORD命令修改root用户的密码,参考如下:SET PASSWORD = PASSWORD('root123456')
登录MySQL
使用mysql命令登录MySQL服务器,运行MySQL的命令时,会提示需要设置root用户密码
设置开机自启动
/etc/init.d/mysql start
设置完成后重启系统,使用natstat –nat命令可看到MySQL的3306端口
至此我们已经安装好了mysql数据库,当然现在我们的数据库还不支持远程连接,远程连接会出现以下代码:1130,ERROR 1130: Host 192.168.0.10 is not allowed to connect to this MySQL server,可以通过以下以下来解决
改表法:在本机登入mysql后,更改“mysql”数据库里的“user”表里的“host”项,从”localhost”改为'%'。
mysql>
mysql>use mysql
mysql>select 'host' from user where user='root'
本人博客供参考
网页链接
下载mysql源安装包shell>wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
安装mysql源shell>yum localinstall mysql57-community-release-el7-8.noarch.rpm
检查mysql源是否安装成功
yum repolist enabled | grep “mysql.-community.”
安装MySQL
yum install mysql-community-server
启动MySQL服务
shell>systemctl start mysqld
查看MySQL的启动状态
shell>systemctl status mysqld
开机启动
shell>systemctl enable mysqld
shell>systemctl daemon-reload
修改root本地登录密码
mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:
shell>grep ‘temporary password’ /var/log/mysqld.log
shell>mysql -uroot -p
mysql>ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘MyNewPass4!’
或者:
mysql>set password for ‘root’@’localhost’=password(‘MyNewPass4!’)
注意:mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误
添加远程登录用户
默认只允许root帐户在本地登录,如果要在其它机器上连接mysql,必须修改root允许远程连接,或者添加一个允许远程连接的帐户,为了安全起见,我添加一个新的帐户:
mysql>GRANT ALL PRIVILEGES ON . TO ‘yangxin’@’%’ IDENTIFIED BY ‘Yangxin0917!’ WITH GRANT OPTION
以上部分个人实践过,以下内容待实践
数据库存emoji 表情问题
mysql>SHOW VARIABLES WHERE Variable_name LIKE ‘character_set_%’ OR Variable_name LIKE ‘collation%’
+————————–+——————-+
| 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 |
| collation_connection | utf8_general_ci |
| collation_database | latin1_swedish_ci |
| collation_server | latin1_swedish_ci |
+————————–+——————-+
10 rows in set (0.02 sec)
可以看到我的mysql版本是5.7的,utf8mb4有一个使用限制,mysql版本必须是5.5以上,大家需要注意,我目前用的ubuntu系统是16.04的。当前mysql的字符集配置如上表,我们的目的是更改成utf8mb4。
3.找到mysql的配置文件,可用命令
sudo find / -name my.cnf
我的配置文件位置如下,个别的位置有所不同
/etc/mysql/mysql.conf.d/mysqld.cnf
4.修改配置文件
在原文中添加以下内容:
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect=’SET NAMES utf8mb4’
原文件中无“[client]”和“[mysql]”,需要手动添加上。
……
Here is entries for some specific programs
The following values assume you have at least 32M ram
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
#
* Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect=’SET NAMES utf8mb4’
#
Instead of skip-networking the default is now to listen only on
……
5.重启mysql服务
sudo service mysql restart
6.查看结果
mysql>SHOW VARIABLES WHERE Variable_name LIKE ‘character_set_%’ OR Variable_name LIKE ‘collation%’
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect…
Connection id: 3
Current database: * NONE *
+————————–+——————–+
| Variable_name | Value |
+————————–+——————–+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| collation_connection | utf8mb4_unicode_ci |
| collation_database | utf8mb4_unicode_ci |
| collation_server | utf8mb4_unicode_ci |
+————————–+——————–+
10 rows in set (0.00 sec)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)