yum install mysql mysql-devel mysql-server
是找不到mysql-server包的,因为Centos7中用MariaDB代替了mysql数据库。
查了资料,MariaDB是优于mysql的,但是我们开发环境全是用的mysql,并不敢轻易换,待我明天做下测试,如不影响现有产品的使用情况,再决定是否更新。
以下是装mysql-server的过程及出现问题的解决办法:
1、# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
# rpm -ivh mysql-community-release-el7-5.noarch.rpm
# yum install mysql-community-server
2、[root@localhost /]# whereis mysqld
mysqld: /usr/sbin/mysqld
[root@localhost /]# mysqld
报如下错误:
Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
解决方法:
[root@localhost /]# mysql_install_db --user=mysql 初始化数据库即可
3、初次安装mysql是root账户是没有密码的
[root@localhost /]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.26 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> insert into mysql.user(host,user,password) values("%","newmedia",password("newmedia123456"));
ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value
原因:在我的配置文件my.cnf中有这样一条语句
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
指定了严格模式,为了安全,严格模式禁止通过insert 这种形式直接修改mysql库中的user表进行添加新用户
解决办法:
将配置文件中的STRICT_TRANS_TABLES删掉,即改为:
sql_mode=NO_ENGINE_SUBSTITUTION
然后重启mysql即可
Query OK, 1 row affected, 3 warnings (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'newmedia' IDENTIFIED BY 'newmedia123456' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> Ctrl-C -- exit!
Aborted