linux安装mysql

一安装mysql
1.rpm -qa | grep mysql  // 这个命令就会查看该操作系统上是否已经安装了mysql数据库
2.rpm -e --nodeps mysql  // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除
3.yum list | grep mysql 命令来查看yum上提供的mysql数据库可下载的版本
4.yum install -y mysql-server mysql mysql-deve

二数据库初始化
1.我们在安装完mysql数据库以后,会发现会多出一个mysqld的服务,这个就是咱们的数据库服务,
我们通过输入 service mysqld start 命令就可以启动我们的mysql服务。
注意:如果我们是第一次启动mysql服务,mysql服务器首先会进行初始化的配置:
[root@xiaoluo ~]# service mysqld start

初始化 MySQL 数据库: WARNING: The host 'xiaoluo' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h xiaoluo password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

[确定]
正在启动 mysqld: [确定]

2.我们在使用mysql数据库时,都得首先启动mysqld服务,我们可以 通过
chkconfig --list | grep mysqld 命令来查看mysql服务是不是开机自动启动
3.我们发现mysqld服务并没有开机自动启动,我们当然可以通过
chkconfig mysqld on 命令来将其设置成开机启动,这样就不用每次都去手动启动了

4.mysqladmin -u root password 'root'  // 通过该命令给root账号设置密码为 root

5.此时我们就可以通过 mysql -u root -p 命令来登录我们的mysql数据库了
(进入databases:show databases;)


三:mysql数据库的主要配置文件
1./etc/my.cnf 这是mysql的主配置文件
2./var/lib/mysql mysql数据库的数据库文件存放位置
3.自己创建一个新库(create database xxx;)
4./var/log mysql数据库的日志输出存放位置

原文地址:https://www.cnblogs.com/jayson-0425/p/9854383.html